为什么我的部分渲染两次?

时间:2016-08-10 19:18:14

标签: ruby-on-rails ajax

  (19.2ms)  commit transaction
  Rendered article_comments/_article_comment.html.haml (0.5ms)
  Rendered article_comments/create.js.erb (4.5ms)

在我的create.js.erb中我有

  $(".article-contents").prepend('<%= j render @article_comment %>');
  $("#article_comment_content").val("")
_article_comment.html.haml

中的

  = article_comment.user.first_name.upcase
  said:
 .content= article_comment.content

在article_comments_controller

def create
  @article = Article.find(params[:article_id])
  @article_comment = current_user.article_comments.build(article_comment_params)
  @article_comment.user_id = current_user.id
  @article_comment.article_id = @article.id
  if @article_comment.save
    respond_to do |format|
      format.html { redirect_to @article}
      format.js
    end
  else
    flash[:notice] = "Comment cannot be empty!"
    redirect_to article_path(@article)
  end
end

在我的show.html.haml

.article-contents
  = render @article_comments.desc

0 个答案:

没有答案
相关问题