Changing Rails Boolean with a Button
I suddenly realized how to change a boolean with a button in a much easier way that the post I did yesterday. All I did was make a form with one hidden field (the boolean that I want to change) and just show the submit button.
Here is all that I put in my view:
<% if case.hidden? %>
<%= form_for case do |f| %>
<%= f.hidden_field :hide, value: false %>
<%= f.submit 'Unhide' %>
<% end %>
<% else %>
<%= form_for case do |f| %>
<%= f.hidden_field :hide, value: true %>
<%= f.submit 'Hide' %>
<% end %>
<% end %>
I didn’t need to make any extra routes or methods. Very simple and exactly what I was looking for.