It cannot be this difficult, especially in rails. Here is my form code in a partial for the index action of a controller:
<% form_tag({:controller => controller_name, :action => 'index'}, {:method => :get, :class => 'form'}) do %> <div class="columns"> <div class="column left"> <p> <%= label_tag :search, "Search by: " %> <%= select_tag :search_by, options_for_select(a, params[:search_by]) %> <%= text_field_tag :search, params[:search] %> <%= submit_tag " Search", :name => 'search_button' %> </p> </div> <div class="column right"> <% if status_array %> <p> <%= label_tag :filter, "Filter by: " %> <%= select_tag :filter, options_for_select(status_array, params[:filter]) %> <%= submit_tag " Filter", :name => 'filter_button' %> </p> <% end %> </div> </div> <div class="clear"></div> <% end %>
I am trying to detect in the index action of this controller which button is clicked. Unfortunately, no matter which button I click, I get the same parameters and no indication of the button clicked. If I change the method to post as shown below:
<% form_tag({:controller => controller_name, :action => 'index'}, {:method => :post, :class => 'form'}) do %>
then the form posts to the create action! I don't get it, I am asking it to execute index action explicitly right? Anyway, when I change to post method then it is easy to detect which button was clicked.
Please help!
Thanks for your time.
Bharat