bigpotato
bigpotato

Reputation: 27497

Rails 3: How do I mix form params and URL params?

I am working on a legacy app and am trying to upgrade it to Rails 3. Currently when I do a search I get the URL: http://localhost:3000/search/external_search/?keyword=argentina. However, when I try to filter out the results, I get http://localhost:3000/search/external_search/?order=Name:ASC, without the keyword parameter in the URL. Since there wasn't a keyword params, the filter wouldn't work. This was messing up my filter, so I decided to add a hidden field tag

<%= hidden_field_tag 'keyword', @search.text %>

which makes it work, but the URL didn't change. I want it to look like:

http://localhost:3000/search/external_search/?keyword=argentina&order=Name:ASC

Where exactly would I accomplish this? In the controller or the form?

Upvotes: 1

Views: 182

Answers (1)

Baldrick
Baldrick

Reputation: 24340

If you want to see the parameters of the submited form in the URL, you must use GET method instead of POST.

Add the option :method => :get to the form_for or form_tag enclosing the <%= hidden_field_tag 'keyword', @search.text %>

Upvotes: 1

Related Questions