Link_to Current Page Plus Additional Parameters In Rails

Posted by Weston Ganger

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:

Article Topic:Software Development - Rails

Date:July 19, 2016

Recommended Posts