Question

I am setting up an active_admin app and have the following STI structure

class Organization < ActiveRecord::Base
   attr_accessible :name, :type
end

class Contractor < Organization
  def self.model_name
    return Organization.model_name
  end
end

class Supplier < Organization
  def self.model_name
    return Organization.model_name
  end
end

Using Active Admin I have a resource for Organization. Works fine for edit but not for the show action.

e.g. I created a new organization and set the type to 'Supplier' (also tried with Contractor) then when I save it redirects to /admin/organizations/20

I get the following error at that path

undefined method `association_class' for nil:NilClass


Extracted source (around line #1):

1: insert_tag renderer_for(:show)

BUT: works fine to go to /admin/orgnizations/20/edit

Anyone able to tell me what I am doing wrong?

Thanks

Was it helpful?

Solution

OK. So..... as it turns out my issue was that I had an association with organization called 'owner' using the User class.

To fix this issue (which I still don't fully understand I simply did an override of the show action active admin like so

ActiveAdmin.register Organization do

  show do |ad|
    attributes_table do
      row :name
      row :owner do |record|
        owner = User.find(record.owner_id)
        link_to owner.full_name, admin_user_path(owner)
      end
      row :type
    end
    active_admin_comments
  end
end

Basically this override gave me better control over how active admin fetches the owner.

Hope this helps someone else and please let me know if there are better solutions out there :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top