Reputation: 25542
Inside of a rails app that I am working, I modified the link_to
helper slightly:
def link_to(*args, &block)
args[1] = params[:client_id].present? ? "#{args[1]}?client_id=#{params[:client_id]}" : args[1]
super
end
I did this so I wouldn't have to add the :client_id => params[:client_id]
every time I wrote a link_to
inside of the app. Well, I have kind of pigeon holed myself with the following problem...
If I have this link_to
:
<%= link_to "Continue to billing info", add_product_path(:product_id => @product.id), :class => 'btn' %>
Using my link_to
helper creates a link, like so:
http://localhost:3001/orders/add_product?product_id=35?client_id=HT274848772
I am at a slight loss on how to modify my helper so that the link will work as normal while including the :client_id
param...
Upvotes: 0
Views: 111
Reputation: 5688
You want to add your parameter to the link url, not to the link itself. Maybe you should rewrite the url_for helper, which is the helper used by all of the url helpers ( http://apidock.com/rails/ActionView/Helpers/UrlHelper/url_for )
Upvotes: 1