I have 2 buttons sitting in an if else method and the first button is suppose to allow the user to change a boolean from false to true. Then if the model shows it is true it will show the other button which is a delete button. I cant get the toggle button (top one) to work right the delete is fine. Here is how it stands now.
def which_button(reportapproval)
if reportapproval.user_approved == false
button_to "Approve this Manager?", { controller: "users/reportapprovals", id: @reportapproval.id, action: "#not sure what goes here" }, method: :#not sure what goes here, data: {confirm: "Are you sure you want to give this manager access to your report?" }
else
button_to "Remove this Manager", { controller: "users/reportapprovals", id: @reportapproval.id, action: "destroy" }, method: :delete, data: {confirm: "Are you sure you want to remove this manager's access to your report?" }
end
end
But I keep getting the error Post route no found which i know is not right. I want this to toggle a boolean in the reportapproval model. Please show me what I need to do.
For this you need to make a new action in the users/reportapprovals
controller which will set reportapproval.user_approved
to true
when the user click on the first button. In the first button in the action attribute add the new action created. Also take care to mention the same action in routes. To avoid mentioning the controller and action you can also specify the path of new route created. So this is what you need to do. This can be done using AJAX too or just normally by page reloading.