Ruby on Rails
TutorialStepThree

<— TutorialStepTwo | Tutorial | TutorialStepFour (Creating a model) —>

Create New Controller

Create a new controller (UnderstandingControllers) using the ‘script/generate controller’ generator
(run with no arguments for documentation).

We’ll create a controller called Friends:

./script/generate controller Friends list view new edit

Note: in Windows run as:

ruby script/generate controller Friends list view new edit

Your output will be similar to this:

$ ruby script/generate controller Friends list view new edit
      exists  app/controllers/
      exists  app/helpers/
      create  app/views/friends
      exists  test/functional/
      create  app/controllers/friends_controller.rb
      create  test/functional/friends_controller_test.rb
      create  app/helpers/friends_helper.rb
      create  app/views/friends/list.rhtml
      create  app/views/friends/view.rhtml
      create  app/views/friends/new.rhtml
      create  app/views/friends/edit.rhtml

What is happening in this step?

A controller called

friends_controller.rb
is created in the
app/controllers
directory. The controller will have 4 routines
(‘list’, ‘view’, ‘new’, ’edit’) created inside of it. Later in the tutorial we will edit these routines so that they produce meaningful output.

For each of these four routines in the new controller class, a view template .rhtml file has also been generated.

<— TutorialStepTwo | Tutorial | TutorialStepFour (Creating a model) —>