A Ruby on Rails Journey

June 14, 2010

Setting Up Teams

Filed under: TenthHole — Dick @ 1:11 am

The first object I’m going to create is a Team object. It only has one property: name. I opened a DOS window, navigated to my app’s directory and typee:

C:\Ruby186\tenthhole>ruby script/generate scaffold Team name:string
      exists  app/models/
      exists  app/controllers/
      exists  app/helpers/
      create  app/views/teams
      exists  app/views/layouts/
      exists  test/functional/
      exists  test/unit/
      create  test/unit/helpers/
      exists  public/stylesheets/
      create  app/views/teams/index.html.erb
      create  app/views/teams/show.html.erb
      create  app/views/teams/new.html.erb
      create  app/views/teams/edit.html.erb
      create  app/views/layouts/teams.html.erb
      create  public/stylesheets/scaffold.css
      create  app/controllers/teams_controller.rb
      create  test/functional/teams_controller_test.rb
      create  app/helpers/teams_helper.rb
      create  test/unit/helpers/teams_helper_test.rb
       route  map.resources :teams
  dependency  model
      exists    app/models/
      exists    test/unit/
      exists    test/fixtures/
      create    app/models/team.rb
      create    test/unit/team_test.rb
      create    test/fixtures/teams.yml
      create    db/migrate
      create    db/migrate/20100614005533_create_teams.rb

Generating a scaffold will create default code that, while not exactly what you want, will give you working code right off the bat. In addition to the models, views, and controllers it creates, it also creates a database migration file. To get my database up to date, I have to run the migration. From the command prompt:

C:\Ruby186\tenthhole>rake db:migrate
(in C:/Ruby186/tenthhole)
==  CreateTeams: migrating =========
-- create_table(:teams)
   -> 0.0010s
==  CreateTeams: migrated (0.0030s)

Let’s see where I am now. From the command prompt, I start the web server (ruby script/server) and point my browser to http://localhost:3000.

Not much there, but no errors. Now I can start adding teams by clicking on the New Team link.

No fancy names here, just numbers. And one ‘team’ that all available substitutes will belong to. That’s it for teams. I can add, delete, and edit the teams all with the code the scaffolding generator created.

Advertisement

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.