Created
June 3, 2013 18:08
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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