In my application everything works fine, but in my Active Admin backend I don't get my user roles displayed on screen.
I have two models "User" and "Roles":
class Role < ActiveRecord::Base
has_and_belongs_to_many :users, :join_table => :roles_users
end
class User < ActiveRecord::Base
has_and_belongs_to_many :roles, :join_table => :roles_users
end
I get it to work in the rails console:
ruby-1.9.2-p290 :006 > user.roles
=> [#<Role id: 3, name: "Student">, #<Role id: 2, name: "Supervisor">]
ruby-1.9.2-p290 :007 > user.roles[0].name
=> "Student"
ruby-1.9.2-p290 :008 > user.roles[1].name
=> "Supervisor"
And I tried several ways of implementing this in Active Admin DSL (one of it):
ActiveAdmin.register User do
index do
column :email
column "Role" do |user|
user.roles.each do |p|
p.name
end
end
end
end
Could somebody please help me? How do I get it to work in DSL of Active Admin?