In this challenge assignment, you will use everything learned about CRUD during this chapter to create a PagesController and a SectionsController. Create the controllers, define the routes, write the code for the controller actions, and add the necessary HTML to the view templates.
(cymbal burst) - [Instructor] We are ready for a challenge assignment. In this challenge, you will use what you've learned in the last two chapters to create CRUD actions for the pages and sections. Here are the Objectives for your assignment. From the command line, generate a PagesController and a SectionsController, and remember, when you're generating the controllers, you also can specify the CRUD templates that you want it to create as placeholders at the same time. Then, you'll want to go into your routes file, and add resourceful routes for the pages and sections.
Then, write controller actions for the major parts of CRUD. We're gonna have actions for index, show, new, create, edit, update, delete, and destroy. Try and write the controller actions without peeking at the SubjectsController. It's okay to look if you get stuck, but if you simply copy and paste from the start, you won't learn nearly as much as if you try it on your own. However, it is a good idea for you to copy and paste the HTML from the subjects templates that we've already seen in order to get templates for your pages and for your sections.
You will need to modify them to work with the new controllers and actions, and the pages and sections are gonna have different attributes than the subject, so you'll want to go to your database schema to review what all of those columns are. All of our forms should update all of the columns on those tables. Regardless of what kind of attribute it is, use that text field helper for all of the form fields. We'll learn how to use other types of form helpers later on. This challenge should take about 30 to 40 minutes to complete. Refer back to the movies in this chapter and the one right before if you get stuck.
When you're done, be sure to watch the solution video where I will show you the solution that I came up with. Good luck.
- Creating and configuring a new Ruby on Rails project
- Generating controllers and views
- Handling server requests
- Using different types of routes
- Rendering and viewing templates
- Generating migrations and models
- Creating, updating, and deleting records
- Finding records with queries
- Understanding relationship types
- Writing controllers for CRUD
- Working with layouts and helpers
- Managing application assets
- Building forms
- Validating data
- Authenticating users
Skill Level Beginner
1. What Is Ruby on Rails?
2. Get Started
3. Controllers, Views, and Dynamic Content
4. Databases and Migrations
5. Models and ActiveRecord
7. CRUD, REST, and Resourceful Routes
8. Controllers and CRUD
9. Layouts, Partials, and View Helpers
12. Data Validation
13. Controller Features
14. User Authentication
15. Improve the Simple CMS
Next steps1m 44s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.