We have a model that belongs to another model which has a composite key, e.g. (fictitious key)[place_id, event_hour, event_min] belongs_to :place, class_name: "Place", foreign_key: Place.primary_key, optional: true
Expected behaviorThe page should load Actual behaviorWhen we try to load the page for the model we get an errorundefined method 'to_sym' for an instance of Array #<ActionView::Template::Error: undefined method 'to_sym' for an instance of Array>/path/to/ruby/version/lib/ruby/gems/3.4.0/gems/activeadmin-3.3.0/lib/active_admin/resource/attributes.rb:24:in 'block in ActiveAdmin::Resource::Attributes#foreign_methods'
https://github.com/activeadmin/activeadmin/blob/master/lib/active_admin/resource/attributes.rb#L24 r.foreign_key.to_sym chokes on the foreign key[place_id, event_hour, event_min]
Suggestions: If that is a column to view / show, then allow it to handle arrays: index_by do |r| key = r.foreign_key key.is_a?(Array) ? key.join("_").to_sym : key.to_sym end
Or reject any non-standard keys so we don't show those columns / links? def foreign_methods @foreign_methods ||= resource_class.reflect_on_all_associations. select { |r| r.macro == :belongs_to }. reject { |r| r.chain.length > 2 && !r.options[:polymorphic] }. reject { |r| !r.foreign_key.is_a?(String) }. index_by { |r| r.foreign_key.to_sym }end
### How to reproduce
Having a way to reproduce your issue will help people confirm, investigate, and ultimately fix your issue. You can do this by providing an executable test case. To make this process easier, please use [our bug report template script].
Copy the content of the appropriate template into an.rb file and make the necessary changes to demonstrate the issue. You can execute it by running
ruby the_file.rb in your terminal. If all goes well, you should see your test case failing.
[our bug report template script]:https://github.com/activeadmin/activeadmin/blob/master/tasks/bug_report_template.rb Sorry, I haven't had time to reproduce. If needed, I will try to do that, but hopefully the issue is apparent above.
|