You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Elberet edited this page Apr 7, 2012
·
3 revisions
In order to user CanCan in the scope of a custom action, you need get the ability object from the controller. Here is an example where a Activate / Deactivate button is shown to the user.
(See also Add custom actions and buttons)
action_item :only => :show do
user = User.find(params[:id])
if user.active
link_to("Deactivate", deactivate_admin_user_path(user), :method => :put) if controller.current_ability.can? :deactivate, User
else
link_to("Activate", activate_admin_user_path(user), :method => :put) if controller.current_ability.can? :activate, User
end
end