Rails

Link_to Current Page Plus Additional Parameters In Rails

Posted by Weston Ganger on July 19, 2016

Sometimes you need to create a link to the same page with the current parameters plus some additional params for example link to the pdf format of the same page.


# Using link_to
<%= link_to "Export as PDF", params.merge(format: :pdf) %>
# or assuming the current path is users_path
<%= link_to "Export as PDF", users_path(params.merge(format: :pdf)) %>

# If you just want the url
<%= url_for params.merge(format: :pdf) %>
# or assuming the current path is users_path
<%= users_path(params.merge(format: :pdf)) %>


Related External Links:


Posted in Rails and Tagged with rails 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts