开发者

Some problems with CanCan

开发者 https://www.devze.com 2023-01-05 18:10 出处:网络
(sorry for my English ;) I started to use CanCan from rbates, this is awesome gem, but I have some problems:

(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
0

精彩评论

暂无评论...
验证码 换一张
取 消