0

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?

6
  • Why is :id 'admin', shouldn't it be an integer? Can you us the migration file for Role?
    – Donovan
    Dec 18, 2013 at 21:08
  • Sorry, id is int. I have just edited Dec 18, 2013 at 22:08
  • Are you sure you added resource_id in your model?
    – Donovan
    Dec 18, 2013 at 22:10
  • Yes i m sure. I m going to post schema.rb Dec 18, 2013 at 22:20
  • What does your Role ActiveAdmin resource file contain? Please clarify what you are expecting. Do you want it to display a resource_id column in addition to the default columns? Dec 19, 2013 at 0:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.