Is there any easy tutorial for roles? I found that Devise is great & easy solution for authorization. And then when it comes to Cancan with Rolify there's a confusion eclipse for beginners like me.
Currently I'm defining roles in ability.rb:
if user.has_role? :admin
can :manage, :all
else
can :read, :all
end
And then, in the controller, I'm checking like in this example:
def destroy
ability = Ability.new(current_user)
if ability.can? :delete, :all then
@post = Post.find(params[:id])
@post.destroy
end
respond_to do |format|
...
end
My question is - I have a strange feeling the check if ability.can? :delete, :all then is redundant in this example. So is my code ok or I really got it wrong? Thanks