_Open app/controllers/comments_controller.rb and change the create method to respond to AJAX requests as follows:_
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.create!(comment_params)
respond_to do |format|
format.html { redirect_to @post }
format.js { redirect_to @post }
end
end
we must remove the { redirect_to @post } block's of format.js, because with this line Rails no process the create.js.erb file and not send via Ajax the comment created.
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.create!(comment_params)
respond_to do |format|
format.html { redirect_to @post }
format.js
end
end
On this part of the guide
the section:
_Open
app/controllers/comments_controller.rb
and change the create method to respond to AJAX requests as follows:_we must remove the
{ redirect_to @post }
block's offormat.js
, because with this line Rails no process thecreate.js.erb
file and not send via Ajax the comment created.