Rails 4 rendering a partial with ajax, jquery, :remote => true, and respond_to

后端 未结 3 1841
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-02 11:52

It seems like rendering a page dynamically with AJAX in response to a submitted form is common. None of the other similar questions are focused around how to do this in a g

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-02 12:14

    You should use JS views (which have "js.erb" extension), something like "create.js.erb" for create controller action. Then, add format.js to the respond_to do |format| ... end block. And add remote: true parameter to your form. Notice: js.erb should include Javascript code you need to be included, like:

    $("tbody#items").append("<%= j render(partial: 'your_partial_path') %>")
    

提交回复
热议问题