I’m using
link_to 'My link', path(:arg1 => session[:arg1], :arg2 => session[:arg2],:arg3 => anyobject.id), :method => :post
but the HTML link being generated includes (arg1,arg2,arg3) as URL query parameters.
How can remove them? Did I miss something in the documentation?
A
link_towill always put the arguments into the query string as it is creating a get-style HTML link – even if you put:method => :postthat just appends an extra (“special”) argument_method.What I think you really want is a
button_tolink – which will make it into a sort of form-post. It works the same, but it saysbutton_toinstead (for example,button_to 'My link', path(:params => :go_here). The downside is that it will look like a button. But you can give it a CSS class (eg “unbutton”) and then change the styling on that CSS class to make it not look like a button.Alternatively, if what you really want is actually to have no
paramspassed to the controller at all… then just don’t include them when making your link (for example,link_to "My link" path– there’s no need for:postif you don’t want to post anyparams).Finally, if what you want is for the
paramsto become a part of the URL (for example,stuff/[param_1]/more_stuff/[param_2], etc.) then you need to update your routes to include these parameters as options. Have a look at the routing section of the rdoc for how to do that.