Partial templates, or “partials” for short, allow developers to create reusable HTML fragments that can then be rendered inside other templates. Partial templates are always named with an underscore as the first character of the file name. Variable values can be passed to partials when they are rendered, making them flexible and useful tools to prevent repeating code. Forms are common uses for partials because forms are often similar for both creating and updating records.
- [Voiceover] In the last movie,…we learned how to reuse HTML…for our layout in each of our view templates.…In this movie, we will learn about partial templates…also called "partials" for short, which allows us…to create usable HTML fragments and to not repeat ourselves…as much as possible.…Let's begin by taking a look at the "New" and…"Edit" templates we created in the last chapter.…Inside subjects/new.html.erb you can see that we've…got this form_for(subject) and then we've got all of the…fields here: Name, Position, Visible, etc.…
Let's take a look at Edit and you'll see that it has…the exact same thing. form_for(subject) and then…it has those same fields. The fields are the same.…Chances are, if we wanted to make a change to one of…these fields, we probably want it to change on both…of these forms. Let's say we wanted to add a new attribute.…Now there's a new column, we do a migration for it.…Now we need to add it to our form- we probably want…to add it to both forms. We're repeating ourselves and…we have to add it in both places and we have to make…
- 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?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
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.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.