Currently working on an app in Rails that has users accept/reject requests from other users. I have a boolean in my database,
t.boolean :accepted, :default => false
I know I'm going to have to make a form that will do a POST/PATCH request but i'm unsure on how to change that value.
You don't need a form here. As you are just trying to update a model instance with a button click, you just need a
link_to with a
route that is defined to perform this action. Considering your model is
Request,the below should work
<%= link_to "Accept", accept_request_path(request) %>
request is the instance which need to be updated.
#routes.rb patch /requests/:id/accept, to: requests#accept, as: :accept_request
or if you want a resourceful route, you can do
resources :requests do patch 'accept', on: :member end
And in the
requests_controller have a
accept method with below code
def accept @request = Request.find(params[:id]) @request.update_attribute(accepted: true) end