adding :find_by option to load_resource - closes #19
This commit is contained in:
@@ -80,6 +80,11 @@ module CanCan
|
||||
# [:+instance_name+]
|
||||
# The name of the instance variable to load the resource into.
|
||||
#
|
||||
# [:+find_by+]
|
||||
# Find using a different attribute other than id. For example.
|
||||
#
|
||||
# load_resource :find_by => :permalink # will use find_by_permlink!(params[:id])
|
||||
#
|
||||
# [:+collection+]
|
||||
# Specify which actions are resource collection actions in addition to :+index+. This
|
||||
# is usually not necessary because it will try to guess depending on if the id param is present.
|
||||
|
||||
@@ -53,7 +53,11 @@ module CanCan
|
||||
end
|
||||
|
||||
def find_resource
|
||||
@options[:singular] ? resource_base.send(name) : resource_base.find(id_param)
|
||||
if @options[:singular]
|
||||
resource_base.send(name)
|
||||
else
|
||||
@options[:find_by] ? resource_base.send("find_by_#{@options[:find_by]}!", id_param) : resource_base.find(id_param)
|
||||
end
|
||||
end
|
||||
|
||||
def authorization_action
|
||||
|
||||
Reference in New Issue
Block a user