O'Reilly logo

The Cucumber Book, 2nd Edition by Steve Tooke, Aslak Hellesoy, Matt Wynne

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required