I'm using rolify and activeadmin gems. By default rolify create the role model:
#models/role.rb created by rolify
class Role < ActiveRecord::Base
has_and_belongs_to_many :users, :join_table => :users_roles
belongs_to :resource, :polymorphic => true
scopify
end
This is schema.rb:
#db/schema.rb
create_table "roles", :force => true do |t|
t.string "name"
t.integer "resource_id"
t.string "resource_type"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
add_index "roles", ["name", "resource_type", "resource_id"], :name => "index_roles_on_name_and_resource_type_and_resource_id"
add_index "roles", ["name"], :name => "index_roles_on_name"
To manage the roles I have registred the role model in active admin:
$rails generate active_admin:resource Role
This is role in active admin:
#app/admin/Role.rb
ActiveAdmin.register Role do
end
When I go in active admin web page and I click in Roles link the browser show me roles in a table, it's ok. But the fields shown are only this:
#http://localhost:3000/admin/roles
Id => 1
Name => "john"
Resource_Type => "RESOURCE" #ok,but I would like to see also resource_id
Created At => "December 18, 2013 18:33"
Updated At => "December 18, 2013 19:33"
The problem is a missing field resource_id. Since the relationship is polymorphic should also see resource_id well as resource_type.
Have you any ideas?