administrate icon indicating copy to clipboard operation
administrate copied to clipboard

Has_One field does not respect custom views

Open bo-oz opened this issue 5 years ago • 3 comments

  • 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

bo-oz avatar Feb 28 '20 18:02 bo-oz

I observe similar issues.

  • I have a UserDashbaord with a subscription: Field::HasOne. The subscription has an attribute stripe_subscription_id: Hyperlink.with_options(href: ->(data:, **) { "#{Stripe::BASE_URL}/subscriptions/#{data}" }) (my definition). However when shown nested within the user, the subscription's stripe_subscription_id doesn'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 form cus_XXX).
Screenshot 2020-03-03 at 08 48 56
  • I have a CourseDashboard with a course_author: Field::HasOne. When viewing the course, it shows the nested CourseAuthor but its property Program shows #<Program:0x0000556cd8d21be0> instead of a hyperlink to the concerned program with the text coming from its display_resource definition. Similarly, the nested CourseAuthor also has a courses: Field::HasMany which doesn't get displayed properly (I would expect to see the same thing as in the author index page, that is, "N courses".
Screenshot 2020-03-03 at 08 40 18

sedubois avatar Mar 03 '20 08:03 sedubois

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?

pablobm avatar Mar 05 '20 15:03 pablobm

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: Image 2020-03-05 at 10 42 31 AM

But doesn't show up translated when embedded on the parent's show: Image 2020-03-05 at 10 42 50 AM

iamnader avatar Mar 05 '20 17:03 iamnader