Topic: Submitting a form

I am looking for some implementation ideas.

A view has a dropdown. After selecting a value in the dropdown and clicking a submit button, the form gets submitted and calls a method in the view's controller. This method would display a table of data in the same view depending upon the  selection made in the drop down. This works fine.

There is another case where in the dropdown in the view can have a value preselected by using some cookies set on the browser. So now, even without clicking the submit button, the above mentioned method in the controller should be called and a table of data should be displayed according to the default value selected in the dropdown. How can this be achieved?

Re: Submitting a form

So you want the right table shown based on a cookie value? Build a partial that can take either the dropdown value or the cookie value. Simple example:

<table class="<%= filter %>">
<tr><td><%= yourdata %></td></tr>

Then you pass the value for "filter" into the partial from your view like so:
<%= render :partial => 'table', :locals => { :filter => params[:filter] || cookies[:filter] } %>

The code above looks for a request parameter named "filter"; if not found, it looks for a cookie by the same name. You might even want to hardcode a default value in case both the request parameter and the cookie are not present.

vinnie - rails forum admin