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