I created _form.html.erb, in which it's coded like this
<%= form_for @book, :html => { :class => 'form-horizontal' } do |f| %>
....
<%= f.submit nil, :class => 'btn btn-primary', :name => 'update' %>
<%= f.submit 'Destroy', :class => 'btn btn-danger', :name => 'destroy' %>
....
<% end %>
Yes, I do have 2 submits in the same form, and both of them have name such as 'update' and 'destroy'.
When the user press destroy button, update action in books_controller will be called.
and it judges whether if it's 'update' or 'destroy' request.
For that, how can I get its name parameter in controller?
update action will be something like this
def update
if params[:books][:name] == 'destroy'
destroy transaction
else
update transaction
end
end
Try this,
<%= f.submit 'Update', :class => 'btn btn-primary', :name => 'submit' %>
<%= f.submit 'Destroy', :class => 'btn btn-danger', :name => 'submit' %>
Now when you Update you will get params[:submit]
as "Update" and
when you Destroy you will get params[:submit]
as "Destroy" in your controller
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With