Reputation: 2866
I have accept/decline as a switch:
<%= form_for @dueler do |f| %>
<%= f.check_box :accept, class: 'someclass', :data => { 'on-text'=>'Decline', 'off-text'=>'Accept'} %>
<script>
$("[class='someclass']").bootstrapSwitch();
</script>
<%= button_tag(type: 'submit') do %>
Save
<% end %>
<% end %>
But I'm trying to make them into two separate buttons. If a user clicks one, how to make it where it would automatically submit with the appropriate :accept
value:
<%= button_tag(type: 'submit') do %>
Accept # submits & makes :accept true
<% end %><br><br>
<%= button_tag(type: 'submit') do %>
Decline # submits & makes :accept false
<% end %>
Upvotes: 2
Views: 612
Reputation: 2082
This is my experience
When you make check box and did not set any value it autometically send boolean value. That means true or false. When Check box is checked value will be true or one and if box is unckecked then value will be false or 0.
Hope It helps.
Upvotes: 0
Reputation: 1951
You can use f.button to pass a param that you'll use in the controller:
In your view:
<%= f.button "Accept", name: "button_action", value: "accept" %>
<%= f.button "Decline", name: "button_action", value: "decline" %>
In your controller use the param value:
if params['button_action'] == 'accept'
else
end
Upvotes: 3
Reputation: 27747
In your controller... check the value of the submit-button - which will be either "accept" or "decline" and set the boolean based on that.
Upvotes: 0