samedi 23 janvier 2016

How to use CanCanCan with enum field?

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?

Aucun commentaire:

Enregistrer un commentaire