I am using CanCan on Rails 4 (cancancan) and I want to only authorize the current user from accessing the settings page.
For example user id 1 should only be access /settings/1. User id 1 should not be able to view /settings/2 or any other id.
My roles are: admin, user, guest, banned
Ability.rb:
include CanCan::Ability
def initialize(user)
user ||= User.new # guest user (not logged in)
if user.admin?
can :manage, :all
else
can :read, :all
end
end
end
Users Controller:
def settings
@user = User.find(params[:id])
end
settingsas resources in routes? if yes maybe changing it to resource will be a good solution. I mean for any user exists only ONE (own) setting page. - gotva