administrate
administrate copied to clipboard
Has_One field does not respect custom views
- What were you trying to do?
I've overwritten the views for Field::Boolean, to display a FontAwesome icon instead of a true/false text. This works fine when displaying the record itself. But when this record is shown in content of a different record through Field::HasOne, the rendered box does not respect the overwritten views. In other words, it reverts back to showing true/false instead of the icons.
- What did you end up with (logs, or, even better, example apps are great!)?
The box only displays static text and does not render the custom views.
- What versions are you running?
- Rails 5.2.2
- administrate 0.12.0
I observe similar issues.
- I have a
UserDashbaordwith asubscription: Field::HasOne. The subscription has an attributestripe_subscription_id: Hyperlink.with_options(href: ->(data:, **) { "#{Stripe::BASE_URL}/subscriptions/#{data}" })(my definition). However when shown nested within the user, the subscription'sstripe_subscription_iddoesn't show up as a hyperlink as it does when viewing subscription directly, instead it shows up as a plain text (just the user's Stripe ID, of the formcus_XXX).
- I have a
CourseDashboardwith acourse_author: Field::HasOne. When viewing the course, it shows the nestedCourseAuthorbut its propertyProgramshows#<Program:0x0000556cd8d21be0>instead of a hyperlink to the concerned program with the text coming from itsdisplay_resourcedefinition. Similarly, the nestedCourseAuthoralso has acourses: Field::HasManywhich doesn't get displayed properly (I would expect to see the same thing as in the author index page, that is, "N courses".
This looks like the application/show and application/form templates could be refactored so that their main bodies are extracted into partials. Then these partials could be used by has_one/form and has_one/show. I can't tell right now if this would bring new issues. I think it's worth experimenting.
Would anyone be up for a PR?
Similarly the translation files aren't respected when a has_one is shown on the parent show page.
For example this model displays correctly on it's own show:

But doesn't show up translated when embedded on the parent's show:
