Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single Table inheritance Active admin model mapping issue rails 4

I have created a multiple user with single table inheritance here are my models

# user.rb 

class User < ActiveRecord::Base
end

This is user model and all other model are inherit from user in database their is one model which store both type of user and also saving their types

# customer.rb

class Customer < User
end

# space_owner.rb

class SpaceOwner < User
end

**when I map these in active_admin rails 4 is shows me an error **

Showing /home/rabnawaz/.rvm/gems/ruby-2.3.1/bundler/gems/activeadmin-0a5a15b88bff/app/views/active_admin/resource/index.html.arb where line #2 raised:

undefined method `chain' for nil:NilClass
Extracted source (around line #709):
  def chain
    @chain ||= begin
      a = source_reflection.chain
      b = through_reflection.chain
      chain = a + b
      chain[0] = self # Use self so we don't lose the information from :source_type

This is the error I get when I create active_admin files to display users

Can you please give me a solution?

Here are my routes for devise which i m using to create multiple users

devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)

devise_for :customers, :controllers => { 
    :registrations=>"customers/registrations", 
    :passwords=>"customers/passwords"
  },:skip => :sessions
  devise_for :space_owners, :controllers => { 
    :registrations=>"space_owners/registrations", 
    :passwords=>"space_owners/passwords"
  },:skip => :sessions
like image 877
Rabnawaz Avatar asked Mar 17 '26 23:03

Rabnawaz


1 Answers

To give this an answer quoting from https://github.com/activeadmin/activeadmin/issues/3957:

After some research I figured out that this error appears when active_record can't automatically infer the name for a nested association. Workaround to handle this could for instance be using through on nested associations.

It is also not clear from your question if you did register the User sub-classes with ActiveAdmin.

like image 109
Christopher Oezbek Avatar answered Mar 20 '26 13:03

Christopher Oezbek