[英]Rails - adding ajax to partials, 'undefined method `render''
我在ID為“ chapcomments”的div內有一個帶有提交標簽的局部表格-
<%= f.submit "Post", remote: true %>
在正確的視圖文件夾中,我有create.js.erb-
$('#chapcomments').html("<%=j render 'shared/chap_comment_complete' %>");
在控制器中,我有一個格式塊,其中包括
def create
@chap_comment = current_user.chap_comments.build(chap_comment_params)
respond_to do |format|
if @chap_comment.save
format.js
format.html {redirect_to chapter_path(@chap_comment.chapter)}
else
format.html { render :new }
format.json { render json: @chap_comment.errors, status: :unprocessable_entity }
end
end
end
...但是我沒有得到ajax的行為...
我要去哪里錯了?
您已經進行了更改,以使JS位於視圖中正確的js.erb文件中,但是您需要將remote: true
部分從Submit標簽移到form_for
聲明中,否則format.html響應塊將是呈現而不是format.js。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.