Polymorphic field should override dashboard selection from Associative
Created by: monkbroc
Currently Polymorphic
is only an alias for Associative
.
Associative#associated_dashboard
uses the attribute name to select the correct dashboard.
In Polymorphic
this leads to a uninitialized constant
error when calling field.display_associated_resource
during the render of app/views/fields/polymorphic/_index.html.erb
For a polymorphic relation, the correct dashboard should be taken from the class of the associated object if it exists.
My workaround right now is:
<% if field.data %>
<%= link_to(
"#{field.data.class.name}Dashboard".constantize.new.display_resource(field.data),
polymorphic_path([:admin, field.data])
) %>
<% end %>
Do you agree with the approach? Is there a better way to get the associated dashboard name?
I can clean this up and make a PR for this.