I am looking to create a named route from a string and pass an object into it
I am rendering a partial with a local "resource"
ie. render :partial => "listing", :locals => {:resource => @resource}
inside _listing.html.haml i am using the self.send method
self.send("#{resource.class.to_s.downcase}_path()")
this works just fine and creates the resources named route ie. article_path()
but this route needs an object passed in the route ie. article_path(article)
i am trying this
self.send("#{resource.class.to_s.downcase}_path("+resource+")")
and get the error can't convert Article into String
any suggestions?
You should pass the arguments like this :
self.send("#{resource.class.to_s.downcase}_path", resource)
You can simplify Jef's answer (you don't need to use a resource) like so:
send("#{controller_name}_path")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With