Ich versuche, eine der Rolify's Finder Methods gehen (Nr. 3), aber es gibt immer ein leeres Array zurück.Rolify Finder Methode leere Array zurückgeben - Rails
User-Modell:
class User < ActiveRecord::Base
rolify
has_many :forums, dependent: :destroy
end
Forum Modell:
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
Hinzufügen von Rollen:
user.add_role :admin, Forum.find(3)
Testing Rollen:
2.4.0 :043 > user.has_role? :admin, Forum.find(3)
Role Load (21.9ms) SELECT ...
=> true
Ich habe versucht, Forum.find(3).participants
und User.with_any_role :admin, { name: :moderator, resource: Forum.find(3) }
von der Konsole ausgeführt wird, und beide zurückgeben leere Arrays, z:
2.4.0 :027 > Forum.find(3).participants
Forum Load (21.9ms) SELECT ...
User Load (28.7ms) SELECT ...
=> []
Gibt es etwas, was ich bin hier fehlt?
Dank!
Sie eine Rolle noch hinzufügen Sie? – bananaappletw
@bananaappletw Ich habe sicher. – slehmann36
Was ist der Befehl, den Sie eingeben, um eine Rolle hinzuzufügen? Vielleicht könnte ich Ihnen helfen, es zu debuggen. – bananaappletw