Ruby/Rails の次の行について説明してもらえますか?
if user.role? :super_admin
アプリに合わせて、次のように更新しました。
if user.role? :admin
それは失敗しましたが、次のように更新しました:
if user.role? == 'admin'
そして、それは意図したとおりに機能します。何故ですか?
class Ability
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user
if user.role? :super_admin
can :manage, :all
elsif user.role? :product_admin
can :manage, [Product, Asset, Issue]
elsif user.role? :product_team
can :read, [Product, Asset]
# manage products, assets he owns
can :manage, Product do |product|
product.try(:owner) == user
end
can :manage, Asset do |asset|
asset.assetable.try(:owner) == user
end
end
end
end
def role?(role)
return !!self.roles.find_by_name(role.to_s.camelize)
end