Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

When an associated record has a composite key, the resource 'show page' fails#8730

Unanswered
glenpike asked this question inHelp
Discussion options

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 behavior

The page should load

Actual behavior

When 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.

You must be logged in to vote

Replies: 0 comments

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Help
Labels
None yet
1 participant
@glenpike
Converted from issue

This discussion was converted from issue #8716 on May 27, 2025 20:55.


[8]ページ先頭

©2009-2025 Movatter.jp