Named routes from a string with an object

I am looking to create a named route from a string and pass an object to it

I am doing partial with a local "resource"

t render :partial => "listing", :locals => {:resource => @resource}

inside _listing.html.haml I use the self.send method

self.send("#{resource.class.to_s.downcase}_path()")

this works great and creates resources called route i.e. article_path ()

but for this route you need an object traversed along the route that is. article_path (article)

I'm trying to do it

self.send("#{resource.class.to_s.downcase}_path("+resource+")")

and getting an error cannot convert the article to a string

any suggestions?

+5
source share
2 answers

You must pass the following arguments:

self.send("#{resource.class.to_s.downcase}_path", resource)
+10
source

You can simplify Jef's answer (you don't need to use a resource):

send("#{controller_name}_path")
+1
source

All Articles