Reputation: 21487
I have a simple form that looks like so
<% remote_form_for post, :url => post_path(post), :method => :put do |f| -%>
<%= f.submit "Approve" %>
<%= f.submit "Deny" %>
<% end -%>
Which renders
<input type="submit" value="Approve" name="commit"/>
<input type="submit" value="Deny" name="commit"/>
In my controller I have the following logic
@post.approved = params[:commit] == 'Approve' ? true : false
So problem is that if the user clicks the "Approve" button or the "Deny" button the parameter that is sent is that :commit => "Approve"
.
Does anybody know of a bug relating to this or another (simple) way to perform the same functionality?
Thanks.
Upvotes: 0
Views: 603
Reputation: 1805
I think Submit is unique per form (HTML thing) so yopu have two options:
Upvotes: 0
Reputation: 6436
Another option is to override the "name" parameter of the second button.
<%= f.submit "Deny", :name => "commit_deny" %>
Upvotes: 1
Reputation: 6338
JS lib (Prototype I guess) doesn't know what button was pressed. It just serializes the form field values for the Ajax request. When using normal form POST, browsers attach right value to the commit param.
You can add hidden form field (eg action). Then add JS code to set required value of the hidden field when appropriate button is pressed (and before the Ajax request is sent).
Upvotes: 1