0

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.

SupremeA
  • 1,519
  • 3
  • 26
  • 43
  • you need to take the first button to a action in the controller which sets the `reportapproval.user_approved` to true. – Deepesh Feb 06 '15 at 01:26
  • So i should create a unique action in the controller? I did that but wasnt sure how to call the action. Do I call it in the action or method area of this button and whichever it is what goes in the other one of this button. – SupremeA Feb 06 '15 at 01:37
  • Call it in the action as you did in the second one. It calls the action destroy. – Deepesh Feb 06 '15 at 01:40
  • ok I will call it in the action but what goes in the method, update? – SupremeA Feb 06 '15 at 01:42
  • just remove the method or use get or post whatever required/whatever you define in the route. And do remember to make the route of the action you are creating. – Deepesh Feb 06 '15 at 01:46
  • Thanks I was able to get it thru a new method and route. I appreciate the help. – SupremeA Feb 06 '15 at 07:03

1 Answers1

1

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.

Deepesh
  • 6,138
  • 1
  • 24
  • 41