Some problems with CanCan
(sorry for my English ;)
I started to use CanCan from rbates, this is awesome gem, but I have some problems: I have Scrap model and th开发者_开发知识库ere is boolean field :published (so, it means published/not published (draft)).
I have this rule in my ability.rb:
can :create, [Scrap]
can [:update, :destroy], [Scrap] do |object|
object.try(:user) == user
end
So, this object cant be edited/updated/deleted by non-author. I want to do the same with my "show" action (non-author cant read drafts, really? ;) What is the true way to do this?
Thanx all! Andrey Ognevsky
can :show, Scrap do |scrap|
scrap.published || scrap.user == user
end
精彩评论