lib/cancan/controller_resource_finder.rb in cancancan-2.1.1 vs lib/cancan/controller_resource_finder.rb in cancancan-2.1.2
- old
+ new
@@ -11,14 +11,19 @@
adapter.find(resource_base, id_param)
end
end
def find_resource_using_find_by
- if resource_base.respond_to? 'find_by'
- resource_base.send('find_by', @options[:find_by].to_sym => id_param)
- else
- resource_base.send(@options[:find_by], id_param)
- end
+ find_by_dynamic_finder || find_by_find_by_finder || resource_base.send(@options[:find_by], id_param)
+ end
+
+ def find_by_dynamic_finder
+ method_name = "find_by_#{@options[:find_by]}!"
+ resource_base.send(method_name, id_param) if resource_base.respond_to? method_name
+ end
+
+ def find_by_find_by_finder
+ resource_base.find_by(@options[:find_by].to_sym => id_param) if resource_base.respond_to? :find_by
end
def id_param
@params[id_param_key].to_s if @params[id_param_key].present?
end