4

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.

2 Answers 2

8
<%= 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"
Sign up to request clarification or add additional context in comments.

1 Comment

Maybe the answer is out of date as I needed to use something like: submit_tag 'Send', :name => 'MyParameter'
1

Is there a way to accomplish this without revealing the value to the user on the submit button? Say you want to have a different text on the button and a hidden value sent to the controller...

1 Comment

I'd also like to do the same thing but can't find a solution in documentation. It's got to be answered somewhere...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.