I am using Ruby on Rails 3.0.9 and I would like to generate a link_to
URL passing some custom parameters. That is, having a articles_path
(www.my_web_site_name.com/articles) I would like to generate something like the following:
link_to 'Sample link title', ... # Here I should implement the code
# => 'http://www.my_web_site_name.com/articles?param1=value1¶m2=value2&...
How can I code the link_to
statement "a là Ruby on Rails Way" in order to accomplish that? And what if I would_like to 'link_to' an 'article_path(@article)' by passing some custom parameters?
Somewhere I have seen to use something like link_to 'Sample link title', :param1 => 'value1', :param2 => 'value2'
but in this case it isn't involved the named route (the generated URL refers to the current path).
You can send those arguments to the path helper, in this case articles_path. Like this:
link_to 'Sample link title', articles_path(:param1 => 'value1', :param2 => 'value2')
I think that is what you want.
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