Method: CanCan::ControllerAdditions#can?
- Defined in:
- lib/cancan/controller_additions.rb
#can?(*args) ⇒ Boolean
Use in the controller or view to check the user’s permission for a given action and object.
can? :destroy, @project
You can also pass the class instead of an instance (if you don’t have one handy).
<% if can? :create, Project %>
<%= link_to "New Project", new_project_path %>
<% end %>
If it’s a nested resource, you can pass the parent instance in a hash. This way it will check conditions which reach through that association.
<% if can? :create, @category => Project %>
<%= link_to "New Project", new_project_path %>
<% end %>
This simply calls “can?” on the current_ability. See Ability#can?.
379 380 381 |
# File 'lib/cancan/controller_additions.rb', line 379 def can?(*args) current_ability.can?(*args) end |