Skip to content

Allowing custom find method other than find_by_xxx #335

trestrantham opened this Issue Apr 5, 2011 · 1 comment

2 participants


Suggesting modifying find_resource in controller_resource.rb to allow :find_by_custom option for find methods not adhering to find_by_xxx:

def find_resource
  if @options[:singleton] && parent_resource.respond_to?(name)
  elsif @options[:find_by]
    resource_base.send("find_by_#{@options[:find_by]}!", id_param)
  elsif @options[:find_by_custom]
    resource_base.send("#{@options[:find_by_custom]}!", id_param)

to allow for

load_and_authorize_resource :find_by_custom => :find_using_slug
ryanb commented Apr 5, 2011

Thanks for the suggestion. I think I prefer the name custom_find but good idea.

Another idea is to continue using the find_by option but make it dual-purpose by checking which method the class responds to.

load_and_authorize_resource :find_by => :find_using_slug

Since it doesn't respond to find_by_find_using_slug it would try find_using_slug. What do you think?

In the meantime you can alias the custom find method to comply to find_by name.

alias_method :find_using_slug, :find_by_slug
@ryanb ryanb closed this in c031f82 May 21, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.