Reputation: 153
Trying to check abilities in view like this:
...
%td= user.zip
%td
- if can? :manage, user
%td= puts "LOLo!"
...
Raise an error in line if:
syntax error, unexpected keyword_else, expecting keyword_end
File abilities.rb:
class Ability
include CanCan::Ability
def initialize(user)
# Define abilities for the passed in user here. For example:
user ||= User.new # guest user (not logged in)
if user.admin?
can :manage, :all
else user.editor?
can :edit, :all
else
can :read, :all
end
end
end
Upvotes: 0
Views: 326
Reputation: 153
Decided. I didn'n implement method admin?
, but I have another one role?
. Change user.admin?
to user.role?
.
Upvotes: 0
Reputation: 13354
This will totally work in HAML. Your initialize
method has two else
conditions - one needs to be an elsif
def initialize(user)
# Define abilities for the passed in user here. For example:
user ||= User.new # guest user (not logged in)
if user.admin?
can :manage, :all
elsif user.editor? # Problem is here
can :edit, :all
else
can :read, :all
end
end
Upvotes: 2