Params Merge and URL sorting/pagination

Okay I figured 80% of this out on my own after some trial and testing. I still need help with params.merge on the forms only. Here's what I did for the rest:

  def sort_column(title, direction)     direction == "asc" ? image = "up.gif" : image = "down.gif"     (link_to image_tag(image, :border=>0, :alt => direction), params.merge(:controller => controller.controller_name, :numteams => (@showall ? 120 : nil), :orderby => title, :sortby => direction))   end   # adds a button to show all teams on tables based on controller name called.   def show_all_teams     (link_to "Show All Teams", params.merge(:controller => controller.controller_name, :numteams => 120, :orderby => 'rank', :sortby => 'asc', :page => 1, :search => nil)) if !@showall   end   # adds a button to show simplified views on tables based on controller ame called..   def show_simple_view     (link_to "Show Simple View", params.merge(:controller => controller.controller_name, :numteams => nil, :orderby => 'rank', :sortby => 'asc')) if @showall || @searchteams   end

I added params.merge to the link tos and it just merged the params with the existing ones with no changes. I had to modify the Show All Teams link to show :page => 1 since it would get stuck if it was on simple view and a page requester was say on 3.. I also had to change the :search => nil so that show all would clear any search results and show all teams.

This entire fix worked for 80% of the content.

Now, I still have issues with my forms. Here are the views:

      <td align="left" valign="middle">         <% form_tag controller.controller_path, :method => 'get' do %>           <%= hinted_text_field_tag :search, params[:search], "Enter Team" %>           <%= submit_tag "Team Search", :name => nil %>         <% end %>       </td>       <td align="left" valign="middle">         <% form_tag controller.controller_path, :method => 'get' do %>           <%= calendariffic_input(true, :compiled_on, 'calendariffic/date.png', 'search_cal', '%Y-%m-%d', params[:compiled_on], {}, {:class => 'borderless'}) %>           <%= submit_tag "Date Search", :name => nil %>         <% end %>       </td>

How do I use params merge with the forms?

Many thanks in advance.

I took a break from this issue and tried to get back to it again today. I even tried implementing hidden fields but that doesn't work as expected. Can anyone offer input into this issue? Advice? Suggestions?

1. What options do I have for building a form using form_tag with params.merge?

I have looked through a lot of sites online and

<% form_tag(params.merge(:compiled_on => params[:compiled_on]), :method => 'get') do %> <%= hinted_text_field_tag :search, params[:search], "Enter Team" %> <%= submit_tag "Team Search", :name => nil %> <% end %>

.. should work..

However, it does not. I still only get search="Florida" and I don't get search="florida"&compiled_on="2009-07-02"..

If a form's submission method is get, then when you submit the form its input elements are serialized and turned into a query string. The standard just say that a ? and this query string is appended to the action attribute (which would probably create an invalid url such as foo?bar=baz?search=Florida ). In practise most browsers seem to just ignore the query string that was part of the action attribute, although I can't see anything in the standards that says this is ok (equally I can't see anything that says that the query strings need to be concatenated in a smart way). Given that the browser is going to junk the query string bit from the form's action attribute you'll need all of your various parameters as form parameters (unless you have routes which push those parameters into the path of the url)..

Fred