can with multiple actions or classes #2

Closed
ryanb opened this Issue Nov 17, 2009 · 3 comments

Projects

None yet

2 participants

@ryanb
Owner
ryanb commented Nov 17, 2009

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.

@ryanb
Owner
ryanb commented Nov 17, 2009

support arrays being passed to 'can' to specify multiple actions or classes - closed by 766fe86

@batdevis

anyone tried something like this?

can [:update, :destroy], [Article, Comment] do |article, comment|
  true
end

it doesn't work for me

can? :update, [@article, @comment]

return always false

bye

Devis_

@ryanb
Owner
ryanb commented Dec 16, 2009

Only one argument is passed to the block. So it would work like this.

can [:update, :destroy], [Article, Comment] do |article_or_comment|
  # ...
end

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|
  # ...
end

can [:update, :destroy], Comment do |comment|
  # ...
end
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment