There’s a much easier way to do this, which I show in this post.

I have a rails model called cases. I’ve added a boolean value (called hide) to cases for not displaying the case in a view. What I wanted to be able to do, was have a button right next to the name of the case. If the value of case.hide is true (meaning the case is hidden), I wanted to show a button that would show “Unhide case” and cause the value to change to false if pressed. And if the value was false, the button would show “Hide case” and change the value to true when pressed. I’m documenting how I did this for myself. It works, but I’m fairly certain that there’s a better way to do this. I just don’t know what it is. Here’s the part of the view with the buttons:
<% if case.hidden? %>
    <%= button_to "Unhide", unhide_case_case_path(id: case.id) %>
  <% else %>
    <%= button_to "Hide", hide_case_case_path(id: case.id) %>
  <% end %>
My routes file:
resources :cases do
    post 'hide_case', on: :member
    post 'unhide_case', on: :member
  end
Cases controller:
def hide_case
	@case = Case.find(params[:id])
	@case.update(hide: true)
	redirect_to cases_path
end

def unhide_case
	@case = Case.find(params[:id])
	@case.update(hide: false)
	redirect_to cases_path
end
Here’s how my routes look:
$ rake routes|grep hide
                    hide_case_case POST   /cases/:id/hide_case(.:format)                cases#hide_case
                  unhide_case_case POST   /cases/:id/unhide_case(.:format)              cases#unhide_case
This works. However, I feel that there should have been a way for me to do this using the regular update method in the controller. The hide\_case and unhide\_case methods are basically just rewriting that method. I tried a few different ways of using the update method, but none of them worked. So until I come up with a better idea, I’ll use this. The one other thing to remember is that button\_to is an automatic POST method. (If I wanted to switch this to a link, I’d have to make some other changes because link\_to is an automatic GET method.) That’s why the routes file uses POST. The standard update uses PATCH. I’m not familiar enough with the differences between POST and PATCH to figure out if that was one of the problems I had with using the update method.