Skip to content

Instantly share code, notes, and snippets.

@churcho
Forked from cpjk/abilitiestest.ex
Created August 23, 2016 16:41
Show Gist options
  • Save churcho/844e5bef5baa71a6d5d26167c2215a80 to your computer and use it in GitHub Desktop.
Save churcho/844e5bef5baa71a6d5d26167c2215a80 to your computer and use it in GitHub Desktop.
defmodule Abilities1 do
defimpl Canada.Can, for: User do
def can?(%User{id: user_id}, action, %Testimonial{id: testimonial_id})
when action in [:create], do: true
def can?(%User{id: user_id}, action, %Testimonial{id: testimonial_id})
when action in [:edit], do: true
end
end
defmodule BetterAbilities do
defimpl Canada.Can, for: User do
# We can declare both action permissions in a single statement
def can?(%User{id: user_id}, action, %Testimonial{id: testimonial_id})
when action in [:create, :edit], do: true
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment