1
我想要得到Rolify's Finder Methods去(3)之一,但它总是返回一个空的数组。Rolify finder方法返回空数组 - Rails
用户模式:
class User < ActiveRecord::Base
rolify
has_many :forums, dependent: :destroy
end
论坛模式:
class Forum < ActiveRecord::Base
resourcify
belongs_to :user
def participants
# Find all users with any role in the forum
User.with_any_role :admin, { name: :moderator, resource: self }
end
end
添加角色:
user.add_role :admin, Forum.find(3)
个测试角色:
2.4.0 :043 > user.has_role? :admin, Forum.find(3)
Role Load (21.9ms) SELECT ...
=> true
我试图从控制台运行Forum.find(3).participants
和User.with_any_role :admin, { name: :moderator, resource: Forum.find(3) }
,并且都返回空数组,e.g:
2.4.0 :027 > Forum.find(3).participants
Forum Load (21.9ms) SELECT ...
User Load (28.7ms) SELECT ...
=> []
有我丢失的东西吗?
谢谢!
你添加任何作用了吗? – bananaappletw
@bananaappletw我当然有。 – slehmann36
你输入什么命令来添加角色? 也许我可以帮你调试它。 – bananaappletw