Skip to content

Instantly share code, notes, and snippets.

@mrpunkin
Created June 3, 2013 18:08
Show Gist options
  • Select an option

  • Save mrpunkin/5700075 to your computer and use it in GitHub Desktop.

Select an option

Save mrpunkin/5700075 to your computer and use it in GitHub Desktop.
Determine object from restful / polymorphic routes, taking into account the possibility that to_param has been overridden for the given object's class.
cls = controller_name.classify.constantize
paramtest = cls.new
paramtest.attributes.map{|name,val| paramtest[name] = name }
to_param = paramtest.to_param
@object = cls.send("find_by_#{to_param}", params[:id])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment