Fixing Segmentation fault on aliasing

This commit is contained in:
fl00r
2012-06-23 18:25:13 +04:00
parent 5f1be25419
commit 925274d29a
2 changed files with 10 additions and 0 deletions

View File

@@ -172,10 +172,16 @@ module CanCan
# This way one can use params[:action] in the controller to determine the permission.
def alias_action(*args)
target = args.pop[:to]
validate_target(target)
aliased_actions[target] ||= []
aliased_actions[target] += args
end
# User shouldn't specify targets with names of real actions or it will cause Seg fault
def validate_target(target)
raise Error, "You can't specify target (#{target}) as alias because it is real action name" if aliased_actions.values.flatten.include? target
end
# Returns a hash of aliased actions. The key is the target and the value is an array of actions aliasing the key.
def aliased_actions
@aliased_actions ||= default_alias_actions