Это мои способности и я Ограниченные пользователи, чтобы они могли читать только их собственные. но если я пройду через маршруты, я все равно могу увидеть индекс других пользователей.cancan method and devize
Я не хочу помещать текущего пользователя в индексный маршрут, потому что тогда я ограничу администратор, потому что у меня есть модели, администратор и пользователь.
class Ability
include CanCan::Ability
def initialize(user)
if user.is_a?(Admin)
can :manage, :all
elsif user.is_a?(User)
can :show, Profile
can :read, Profile do |profile|
profile.try(:user) == user
end
can :update, Profile do |profile|
profile.try(:user) == user
end
can :destroy, Profile do |profile|
profile.try(:user) == user
end
can :create, Profile
else
can :show, Profile
cannot :destroy
cannot :create
end
end
end