Open a Bootstrap Modal to edit a record in Ruby on Rails

后端 未结 2 1237
余生分开走
余生分开走 2021-01-06 15:21

I have a \"user\" model. I have a list of users on the user index page with an edit button beside each. I want to click on the edit button for each user which will open a bo

2条回答
  •  别那么骄傲
    2021-01-06 15:43

    @aquajach has given you the right code to solve your 1st problem. Notice that your problem arose because you did not send the 'user' parameter to the form partial, and instead used @user to build the form, which is the variable you initialized in the index action with new (so it is empty). As @aquajach did to send the right parameter, you need to place the modal code inside the `.each' loop, otherwise there is no way of telling which user's information you want each modal to display.

    Also note that the Edit link_to uses "#" as its url. This means it will link to nowhere, and definitely not go back to the controller on the server (neither to edit, nor to create).

    As for your second question. Notice that the Close button has data-dismiss="modal", but the Save Changes button does not. Append that code, to get it to hide the modal as well.

提交回复
热议问题