This example is provided in the documentation for specifying multiple actions and classes.
can [:update, :destroy], [Article, Comment]
However it still needs to be implemented.
support arrays being passed to 'can' to specify multiple actions or classes - closed by 766fe86
anyone tried something like this?
can [:update, :destroy], [Article, Comment] do |article, comment|
it doesn't work for me
can? :update, [@article, @comment]
return always false
Only one argument is passed to the block. So it would work like this.
can [:update, :destroy], [Article, Comment] do |article_or_comment|
The article_or_comment object can be either one. You can use kind_of? to see which it is, but that kind of defeats the point of doing them together. You should only do this if you can treat both the same (like maybe they both have a user attributes which you're using to define permissions and therefore don't care whether it's a comment or an article.
If you need to change the permission logic depending on if it's a comment or an article, then keep it two separate definitions.
can [:update, :destroy], Article do |article|
can [:update, :destroy], Comment do |comment|