Skip to content

Instantly share code, notes, and snippets.

@HashNotAdam
Last active May 6, 2016 02:46
Show Gist options
  • Save HashNotAdam/d42fd137c8c5b1476700e17534d71e9f to your computer and use it in GitHub Desktop.
Save HashNotAdam/d42fd137c8c5b1476700e17534d71e9f to your computer and use it in GitHub Desktop.
Example of how to reproduce rails_admin issue #2627
# == Schema Information
#
# Table name: companies
#
# id :integer not null, primary key
# name :string(255) not null
# type :string(255) not null
# created_at :datetime
# updated_at :datetime
#
class Company < ActiveRecord::Base
end
# == Schema Information
#
# Table name: companies
#
# id :integer not null, primary key
# name :string(255) not null
# type :string(255) not null
# created_at :datetime
# updated_at :datetime
#
class Client < Company
before_create :set_generic_type
private
# Sub-classed models set the type to Admin::[User Type]::Client instead of
# simply Client
def set_generic_type
self.type = 'Client'
end
end
module Admin
module SuperUser
class Client < Client
# By default, where would include "type = 'Admin::SuperUser::Client'"
default_scope { rewhere(type: 'Client') }
rails_admin do
list do
field :name, :show_link do
searchable :name
end
end
show do
field :id
field :name, :show_link
end
edit do
field :name
end
end
end
end
end
module Admin
module Reseller
class Client < Client
# By default, where would include "type = 'Admin::Reseller::Client'"
default_scope { rewhere(type: 'Client') }
rails_admin do
list do
field :name, :show_link do
searchable :name
end
end
show do
field :name, :show_link
end
edit do
field :name
end
end
end
end
end
@HashNotAdam
Copy link
Author

Example DB migration

class CreateCompanies < ActiveRecord::Migration
  def change
    create_table :companies do |t|
      t.string :name, null: false
      t.string :type, null: false

      t.timestamps
    end
  end
end

@ericcf
Copy link

ericcf commented May 6, 2016

I had to explicitly subclass from ::Client, or Rails admin gave me a "Circular dependency detected while autoloading constant Admin::Reseller::Client".

module Admin
  module Reseller
    class Client < ::Client
...

I'll let you know what else I'm able to figure out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment