activeadmin: undefined method `chain' for nil:NilClass

ActiveAdmin is throwing an error only for one particular model in my application.

screenshot 2015-05-21 20 17 23

There is nothing in the AA file really…

ActiveAdmin.register Parent do
  index do
    column :id
    actions
  end
end

All other admin pages are working.

Thoughts?

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 21 (3 by maintainers)

Most upvoted comments

@rabnawazPikesSoft @timoschilling i’ve faced with same issue my models have a deep nesting example:

class MenuItem < ActiveRecord::Base
  belongs_to :menu
  has_many :option_groups, dependent: :destroy
end

class OptionGroup < ActiveRecord::Base
  has_many :options, dependent: :destroy
  belongs_to :menu_item
end

class Option < ActiveRecord::Base
  belongs_to :option_group
end

and i got same error when filters was on error looks like

undefined method `chain' for nil:NilClass

this error raise in activerecord gem (using activerecord 4.2.6) https://github.com/rails/rails/blob/v4.2.6/activerecord/lib/active_record/reflection.rb#L707-L715

after some research i figure out that this error appear when active_record can automatically infer name for nested association. workaround to handle with this:

class MenuItem < ActiveRecord::Base
  belongs_to :menu
  has_many :option_groups, dependent: :destroy
  #i add below has_many through association and also set source
  has_many :options, through: :option_groups, source: :options
end

After that all works fine with filters. Hope it helps cheers. PS In activerecord 5 chain method was changed maybe this workaround no need anymore for rails 5/activerecord 5