Creating a Controller by Hand

It may be tempting at this point to run a Rails generator to generate the controller, views, helpers, tests, and who knows what other files. We’ll resist this temptation and implement the bare minimum by hand. This way, we don’t end up with a lot of code that isn’t tested and that we might not even need. Let’s map our controller to config/routes.rb:

 Rails.application.routes.draw ​do
  resources ​:users
 end

Add app/controllers/users_controller.rb:

 class​ UsersController < ApplicationController
 def​ show
 end
 end

And a view in app/views/users/show.html.erb with some temporary content:

Get The Cucumber Book, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.