Можете ли вы провести меня через следующую строку 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