我想获得新的评论用ajax而不是页面重新加载更新。我遵循railscast教程,但在我的js控制台中出现500内部服务器错误。我正在阅读其他帖子,很多人都说这是一个部分错误,但我无法弄清楚。注释将重新加载页面之前保存,但不会显示,直到重新加载页面。这里是注释控制器Rails的Ajax 500服务器错误
def create
@post = Post.find(params[:post_id])
@comment = Comment.create(params[:comment].permit(:content))
@comment.user_id = current_user.id
@comment.post_id = @post.id
if @comment.save
respond_to do |format|
format.html {redirect_to post_path(@post.comments)}
format.js
end
else
render 'new'
end
end
在注释目录中的文件create.js.erb。
$('.comment').append('<%= j render @post.comments %>');
评论表单
<%= simple_form_for([@post, @post.comments.build], :remote => true, :input_html => { :data => { :url => '/post/:id', :type => :js } }) do |f| %>
<%= f.input :content, label: "Reply"%>
<%= f.button :submit, "Submit" %>
<% end %>
什么是评论形式命名? – Dbz
Just _form.html.erb – nharvey27
有关此状态的任何更新? – Dbz