action aliases used in definition of abilities #946

drventure opened this Issue Sep 30, 2013 · 1 comment


None yet

1 participant


I've run into a small issue where a dev on the team used an action alias in the abilities.rb file to define the abilities for a particular user. In this case, it was :index defined as an alias for :read (pretty standard stuff).

However, from what I can tell, CanCan searches for aliases in one direction but not the other, so in this case, when a controller checked can? :read, Object, it missed the alias.

I'd think that the can? function should check in both directions for an alias (ie alias to value, and values to their aliases).

I'll investigate and see if I can make that mod myself and post a pull request.


In looking at it, added a call to aliases_for_actions in the expand_actions method appears to do the trick.


def expand_actions(actions) do |action|
    aliased_actions[action] ? [action, *expand_actions(aliased_actions[action])] + aliases_for_action(action) : [action] + aliases_for_action(action)

In other words,when expanding the actions, expand them in both dirs. You'll end up with duplicates in the list, but that doesn't matter, (and could be resolved with a .uniq anyway)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment