reinteractive-open / installfest_guides

The installfest guides
24 stars 29 forks source link

Finish a Basic Blog - Bug in example code. #244

Closed hackvan closed 5 years ago

hackvan commented 5 years ago

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:_

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
RachelleOnRails commented 5 years ago

Thank you @hackvan, I have fixed the guide. Much appreciated.