Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send parameter to controller on submit_tag rails

I have two submit_tag on my form and I would like to send a different parameter on each. How can I do this?

My form view:

<%= form_tag(some_path, :method => "get") do %>
   <%= text_field_tag :number %>
   <%= text_field_tag :name %>
   <%= submit_tag "Op01", class: "btn_search", my_parameter: 1 %>
   <%= submit_tag "Op02", class: "btn_search", my_parameter: 2 %>
<% end %>

And on my controller:

@oper_type = params[:my_parameter]

But when I display the @oper_type it is always nil.

Thanks.

like image 314
Cleiviane Avatar asked Jan 13 '23 04:01

Cleiviane


1 Answers

<%= submit_tag "Op01", class: "btn_search", value: 1 %>
<%= submit_tag "Op01", class: "btn_search", value: 2 %>

@oper_type = params[:commit] # 1 or 2

or a little simplier

<%= submit_tag "Op01", class: "btn_search" %>
<%= submit_tag "Op01", class: "btn_search" %>

@oper_type = params[:commit] # "Op01" or "Op02"
like image 67
megas Avatar answered Jan 15 '23 18:01

megas