我想从用户模型中获取一个说版主的列表,它在这种情况下有效
u = User.new(:name => "n", :surname => "s", :email => "a@m.c", :password => "x")
u.add_role(:moderator)
u.save!
但是如果我像这样将资源分配给用户模型,它不会列出具有角色主持人的用户
u = User.new(:name => "m", :surname => "b", :email => "a@m.c", :password => "x")
u.add_role(:moderator, Post.first)
u.save!
更新
post.rb
class Post < ActiveRecord::Base
attr_accessible :user_id, :content
belongs_to :user
end
用户.rb
class User < ActiveRecord::Base
rolify
end