ruby on rails - Problem after submitting a form -


I'm new to Ruby on Rails and I've made a list with checkboxes inside. I asked here how to get the values ​​checked with the Paramas and I found it to work. This idea is now to take some action with the selected items if I click on a few buttons, and if I click on each other then perform any execution, but always remains on the same page after the postback.

What is happening now is that I am receiving actions, but at the same time for other URLs. For example:

I have found the following forms in my opinion:

  form_tag delete_profiles_path ,: method => : Put do submit_tag 'Delete' @ my_announcements.each do | Ann | Check_box_tag 'announcement []', ann.id end and  

My Profile Controller:

  Delete def #some operation finished  

more routes RB:

  map.resources: profile ,: archive = & gt; {: Delete = & gt; : Put}  

After submitting it, I will be redirected to:

/ profile / complete, and my form / profile / some id / announcements < / P>

.

Besides, what if I add another button like a delete, how can I handle many actions when I click on them on a single URL? / P>

First of all, why do you delete with the put and delete the HTTP method? You must use the default method to delete: use : method = & gt; : Remove and you can also use delete in the control code #destroy , but you are new to display what you want to do , And delete as is the update ).

Second - The name of the button used to submit the form is sent in the parameter , so that you can distinguish the buay parameter which is used to present the button form Was used for.

Thichar - You can not stay on the same page in Rail (or it would be possible, but against rail) it should be like this:

  1. Submit the form to take action in the controller, most of the time its URL is similar to '/ profile' or '/ profile / id' and the action takes place in the prestigious BO method (post, put or delete)

    < / Li>
  2. What you want to do and try to complete the action if this is not possible (For example, verification errors), show the same form with actual values ​​and errors, why it can not be shown. If the user submits a refresh page, and again the parameter, then he should get the same page and the same errors, and the action should not be completed too.

  3. If this controller has completed the request, then redirect it to some other page, it works like this because if the user is a refresh page (if it was redirected If nothing happened, then the new page comes back, if you do not redirect then the user will take the same action for the second time, which is not always for you. This new page can be a page where the form was presented from the course


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -