Javascript RubyonRails Ajax请求没有';在没有页面更新的情况下不会显示

Javascript RubyonRails Ajax请求没有';在没有页面更新的情况下不会显示,javascript,jquery,ruby-on-rails,ruby,ajax,Javascript,Jquery,Ruby On Rails,Ruby,Ajax,我在Rails中构建了一个应用程序,其中包含表格、帖子和文章。我的想法是,当我在posts的页面上时,我可以查看与此帖子相关的所有评论,并添加新的评论。添加后,页面上会立即出现新注释,而不进行页面更新。问题是,当我通过ajax创建评论时,它们不会出现在页面上——我需要更新它。我不明白为什么会这样 create.js.erb var new_comment = $("<%= escape_javascript(render(:partial => @comment))%>").h

我在Rails中构建了一个应用程序,其中包含表格、帖子和文章。我的想法是,当我在posts的页面上时,我可以查看与此帖子相关的所有评论,并添加新的评论。添加后,页面上会立即出现新注释,而不进行页面更新。问题是,当我通过ajax创建评论时,它们不会出现在页面上——我需要更新它。我不明白为什么会这样

create.js.erb

var new_comment = $("<%= escape_javascript(render(:partial => @comment))%>").hide();
$('#comments').prepend(new_comment);
$('#comment_<%= @comment.id %>').fadeIn('slow');
$('#new_comment')[0].reset();
和my_comment.html.erb文件

<%= div_for comment do %>
      <p>
        <strong>Posted <%= time_ago_in_words(comment.created_at) %></strong><br />
        <%= h(comment.body) %>
      </P>
    <% end %>


已发布

你能帮我找出问题出在哪里吗?
提前非常感谢

我在后期展示页面中发现了印刷错误——是用“commetns”而不是“comments”写的。现在一切都正常了
@jphager2,谢谢你的帮助

当我按“添加评论”时,你从ajax(如果你检查firebug或chrome开发工具)那里得到了什么响应?我看到了POST请求,一切正常。然后在“刷新”之后,我得到几个get请求,部分是OK,部分是304“Not modified”错误,它们还有缓存控制字段“no cache”。。。如果这有帮助的话。。。或者我到底应该找什么?对不起,我猜我之前的答案不是你问我的。因为当我不使用ajax时,我会得到与get请求相同的部分,其中一些是正常的,一些有相同的错误。区别在于按“添加注释”后,POST和GET请求一起“自动”生成,w/o refresh304代码不是错误,是一个缓存状态,表明页面已从本地缓存加载…耶304很好。然后只需查找响应主体,它应该是javascript。
def create
    @post = Post.find(params[:post_id])
    @comment = @post.comments.create(comment_params)

    respond_to do |format|
      if @comment.save
        format.html { redirect_to @post, notice: 'Comment was successfully created.' }
        format.json { render :show, status: :created, location: @comment }
        format.js #create.js.erb
      else
        format.html { render :new }
        format.json { render json: @comment.errors, status: :unprocessable_entity }
      end
    end
  end
<%= div_for comment do %>
      <p>
        <strong>Posted <%= time_ago_in_words(comment.created_at) %></strong><br />
        <%= h(comment.body) %>
      </P>
    <% end %>