在我的应用程序中一切正常,但在我的Active Admin后端,我没有在屏幕上显示我的用户角色.
我有两个模型"用户"和"角色":
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
Run Code Online (Sandbox Code Playgroud)
我让它在rails控制台中工作:
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"
Run Code Online (Sandbox Code Playgroud)
我在Active Admin DSL(其中一个)中尝试了几种实现方法:
ActiveAdmin.register User do
index do
column :email
column "Role" do |user|
user.roles.each do |p|
p.name
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
有人可以帮帮我吗?如何让它在Active Admin的DSL中运行?
arrays ruby-on-rails has-and-belongs-to-many ruby-on-rails-3 activeadmin