In simple_form view, the submit button is like this:
<%= f.button :submit, \'Save\' %>
We are trying to pass a params subaction
Use name and value option.
<%= f.button :submit , name: "subaction",value: "update"%>
In your controller you will get params[:subaction] with the value "update"
By specifying f.button :button, type: 'submit'
, we can use the name
and value
attributes as follows to submit using a single param. Notably, the value submitted (e.g., 'cake') may be different from the button text (e.g., 'The Best Cake').
_form.html.erb
<%= f.button :button, 'The Best Cake', type: 'submit', name: 'dessert_choice', value: 'cake' %>
<%= f.button :button, 'The Best Pie', type: 'submit', name: 'dessert_choice', value: 'pie' %>
Controller
def controller_action
dessert_choice = params[:dessert_choice] # 'cake' or 'pie'
end
This approach avoids the need for hidden inputs as @dax mentioned in the comment above.
Tested on Simple Form 3.3.1 with Rails 4.2.
as dax points out,
<%= hidden_field_tag(:subaction, 'update') %>
<%= f.button :submit, 'Save' %>
This will provide the string value 'update' to the routed controller action via the hidden field. It can then be retrieved by the controller with
params[:subaction]