cancancan

How to use cancancan?

[亡魂溺海] 提交于 2019-12-05 03:17:31
问题 I want to give rights to users in my rails app. I have 'admin' who can create, update and delete all posts and comments, 'user' who can create and update only his own comments, and 'guest' who can do none of these. For this I use the gems 'devise' and 'cancancan'. I understand the 'devise' gem, but I don't understand 'cancancan'. In the class ability.rb, how can I write rights for these users (admin, user, guest)? 回答1: Cancancan lets you only define permissions for given context. This context

How to use CanCanCan with enum field?

南笙酒味 提交于 2019-12-04 15:21:32
I got Article model with enum field enum status: [:pending, :done] . Here's my ability file class Ability include CanCan::Ability def initialize(user) user ||= User.new if user.member? can :read, Article.done end end end In view I am trying to render Article.done collection for member but nothings renders. <% if can? :read, Article.done %> <%= render partial: 'article', collection: Article.done, as: :article %> <% end %> Therefore I have a question: is there any possible way to work with enum in CanCanCan? I may be wrong, but I think that enum only creates instance methods: . @article =