Reputation: 18871
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).
Upvotes: 5
Views: 4583
Reputation: 21180
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.
Upvotes: 10