Closed angeloashmore closed 9 years ago
When defining abilities for :index, :new, and :create, _authorize_resource/2 passes the module to can?/3, not a struct.
:index
:new
:create
_authorize_resource/2
can?/3
This means defining abilities requires doing this:
def can?(%User{}, action, Item) when action in [:index, :new, :create], do: true def can?(%User{}, action, %Item{}) when action in [:show], do: true
Rather than just:
def can?(%User{}, action, %Item{}) when action in [:index, :new, :create, :show], do: true
It makes sense in that at index, new, and create, you have no instance of the model so it would not pass a struct.
Maybe this needs to be mentioned in the docs or change the behavior?
Just saw this is mentioned in the @docs, but not in the README. Oops!
@doc
Thanks for pointing that out! I'll add it to the README.md as well :smile:.
When defining abilities for
:index
,:new
, and:create
,_authorize_resource/2
passes the module tocan?/3
, not a struct.This means defining abilities requires doing this:
Rather than just:
It makes sense in that at index, new, and create, you have no instance of the model so it would not pass a struct.
Maybe this needs to be mentioned in the docs or change the behavior?