(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