
- Ruby
- Beginner
About this Course
You've seen how to create a Rails resource using a scaffold. But scaffolds don't offer flexibility in how a resource is set up. Let's create a resource totally by hand to see how it's put together. Along the way, we'll learn another important component of Rails: routes.
What you'll learn
- Routes
- Models
- Views
- Controllers
A Route to an Index Action
In the first stage, we'll read all Page records in the database and display their titles in a list. (Since we won't yet have a form for adding Pages, we'll have to add some via the Rails console.) This first stage will be the most involved, since we'll need to set up a route, a controller, a view, AND a model for our Pages.
14 steps-
Introduction
2:03
-
Creating a Route
4:45
-
Creating a Route
4 questions
-
Viewing Routes
1 objective
-
Adding a Route
1 objective
-
Creating a Controller
2:39
-
Creating a Controller
1 objective
-
Creating a View
1:29
-
Creating a View
1 question
-
Creating a Model
3:32
-
Creating a Model
1 objective
-
Adding Records via Rails Console
3:17
-
Populating the View
8:57
-
Populating the View
2 objectives
A Route to a Read Action
Users can view a list of all our page titles, but they can't view the content of single Pages yet. For our Posts resource, they can click a link on the list of all Posts to view an individual post. Let's set up links to view single Pages as well.
9 stepsRoutes to Create Actions
Our users can view a list of all Pages. They can click a link to view an individual Page. What they CAN'T do right now is create new pages; we had to go into the Rails console to do that. Our next task is to set up a form so that it's easy for our USERS to create Pages, too.
10 steps-
Route for New Pages
3:08
-
Route for New Pets
1 objective
-
Controller Action for New Pages
1:48
-
View for New Pages
5:42
-
Controller Action for New Pets
1 objective
-
View for New Pets
4 objectives
-
Route to Create Pages
1:18
-
Route to Create Pets
1 objective
-
Controller Action to Create Pages
11:27
-
Controller Action to Create Pets
5 objectives
Routes to Update Actions
Now our users can create a new Page. But they'd better get it right the first time, because right now they can't go back and change what they've entered.
Maybe we should fix that. Let's give them a form to allow them to update existing Pages.
6 stepsA Route to a Delete Action
For every resource you create, there may come a time when you don't want it any more. So, let's allow our users to delete Pages.
6 stepsTeacher
-
Jay McGavren
Resident Ruby and Go teacher for Treehouse. Author of Head First Ruby, a tutorial book on the core Ruby language.