This course will be retired on June 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
![](https://videos.teamtreehouse.com/stills/TH-RailsBasics-Stage1-Video3-stills-0.jpg?token=6991e970_8aeba531eff0cfc8ebabcc643f25cda04d50567e)
- 2x 2x
- 1.75x 1.75x
- 1.5x 1.5x
- 1.25x 1.25x
- 1.1x 1.1x
- 1x 1x
- 0.75x 0.75x
- 0.5x 0.5x
That welcome page is cool, but it's time to create some pages that are specific to your app. And we're going to do it using JUST TWO terminal commands. You're about to witness the power of convention over configuration.
A "resource" is a thing that you want users to be able to perform "CRUD" operations on: to create instances of it, read data for it, update data for it, and delete it when they don't want it any more.
A Rails "scaffold" creates a model, view, and controller for a resource, all at once.
In your terminal:
bin/rails generate scaffold ModelName attribute1:type attribute2:type ...
- "rails" runs the Rails command
- "generate" is the Rails subcommand we want to run. We ran the "server" subcommand before, and there are various other subcommands to do various other tasks. The "generate" subcommand will generate some source code files for us.
- "scaffold" is the type of code we want to generate. We'll look at other things we can generate later.
- "ModelName" is the model we want to create a scaffold for.
- Then, we add one or more attributes that we want our model objects to have. These are bits of data that describe the object.
Among the files created will be one with a name like "db/migrate/[date]_create_model_name.rb". This is a "migration file". It's responsible for creating the database table, which will store data for your objects.
If you ever get a "ActiveRecord::PendingMigrationError", in the terminal, type "bin/rails db:migrate". Your migration files will be run, and will set the database up for you.
To see new resources you've created a scaffold for, go to your browser's address bar and add "/model_name" at the end of the URL.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up-
Tad Luedeke
12,677 Points0 Answers
-
Caitlin Scouler
7,082 Points0 Answers
-
Andrew Ackerman
8,347 Points1 Answer
-
Nick McDaniel
962 Points1 Answer
-
Miguel de Luis Espinosa
41,279 Points1 Answer
-
PLUS
Mutsuki Yamaguchi
Courses Plus Student 2,712 Points2 Answers
-
SOS Norway
4,219 Points1 Answer
-
Ali Iftakhar
729 Points1 Answer
-
andynguyen9
1,629 Points2 Answers
-
Abhi Ramani
4,228 Points1 Answer
-
Bhaskar Singh
8,532 Points2 Answers
-
joshua baker
2,276 Points3 Answers
-
Deepak joshi
87 Points2 Answers
View all discussions for this video
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up