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 createsinstance
methods:I was wrong...
--
I'll delete this if it doesn't work; I would be evaluating against the hash of conditions, not the class itself:
Update
Several important things to consider.
Firstly, when using
hash
conditions:This means that you cannot call specific conditions on an "ability" whilst passing a class, it has to be called on an instance of an object.
Secondly, it seems CanCanCan has some issues evaluating
enum
values, which makes the following code necessary:You then need to pass the
article
instance to thecan?
method: