Questions about @dhh code on Writing Software Well for Controllers

I was struck recently by how simplified the code is that @dhh was showing off in his youtube videos recently. I’m trying to learn from it and get my code refactored properly. The questions I’m finding are more of how his code lines up to what the rails generator creates. Below is an example of both of a #create action.

I realize that I probably shouldn’t be comparing these two as they’re made for different purposes, but from viewing both I can’t help but see that one is much more code.

Rails Generated Controller #create

def create

@post =

respond_to do |format|


format.html { redirect_to @post, notice: ‘Post was successfully created.’ }

format.json { render :show, status: :created, location: @post }


format.html { render :new }

format.json { render json: @post.errors, status: :unprocessable_entity }




the top example looks really clear to me.

I can see immediately what it is doing and why.

there is almost no duplication and it is doing ‘controller-type’ work.

what don’t you like about it?

I guess I’m just looking at it from the idea of “less code is usually better code”. And also I’m trying to learn from others that have a better skill set and/or experience than I do. But as I mentioned, perhaps I’m taking a snippet of code from one of his controllers that do not relate to the piece of generated code.