【发布时间】:2016-04-28 11:33:35
【问题描述】:
我正在尝试让新的 cmets 使用 ajax 进行更新,而不是重新加载页面。我遵循了 railscast 教程,但在我的 js 控制台中收到 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 %>
【问题讨论】:
-
评论表单叫什么?
-
这个状态有什么更新吗?
标签: jquery ruby-on-rails ajax