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…
Author
Released
9/28/2016- 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
Duration
Views
Related Courses
-
Ruby: Testing with RSpec
with Kevin Skoglund6h 13m Intermediate
-
Introduction
-
Welcome1m 4s
-
-
1. What Is Ruby on Rails?
-
2. Get Started
-
Create a project6m 45s
-
File structure of a project4m 28s
-
Configure a project10m 15s
-
Access a project3m 38s
-
Routes9m 12s
-
Experiment on your own1m 17s
-
-
3. Controllers, Views, and Dynamic Content
-
Redirect actions6m 4s
-
View templates7m 4s
-
Instance variables3m 56s
-
Links6m 11s
-
URL parameters7m 24s
-
4. Databases and Migrations
-
Introduction to databases7m 53s
-
Create a database2m 27s
-
Migrations3m 4s
-
Generate migrations4m 3s
-
Generate models7m 58s
-
Run migrations8m 22s
-
Migration methods7m 47s
-
Solve migration problems5m 41s
-
-
5. Models and ActiveRecord
-
Model naming5m 52s
-
Model attributes2m 51s
-
The Rails console3m 17s
-
Create records4m 53s
-
Update records3m 16s
-
Delete records2m 29s
-
Find records5m 48s
-
Query methods: Conditions7m 39s
-
Named scopes8m 26s
-
6. Associations
-
Relationship types7m 2s
-
One-to-one associations9m 42s
-
One-to-many associations7m 54s
-
Many-to-many associations: Rich10m 17s
-
Traverse a rich association5m 24s
-
-
7. CRUD, REST, and Resourceful Routes
-
CRUD6m 56s
-
REST5m 51s
-
Resourceful routes6m 54s
-
Resourceful URL helpers4m 5s
-
-
8. Controllers and CRUD
-
Read action: Index6m 31s
-
Read action: Show5m 22s
-
Form basics5m 13s
-
Create action: New4m 54s
-
Create action: Create5m 27s
-
Strong parameters6m 33s
-
Update actions: Edit/update7m 53s
-
Flash hash7m 28s
-
-
9. Layouts, Partials, and View Helpers
-
Layouts8m 33s
-
Partial templates4m 43s
-
Text helpers4m 32s
-
Number helpers4m 22s
-
Date and time helpers3m 39s
-
Custom helpers5m 22s
-
Sanitization helpers8m 53s
-
-
10. Assets
-
Asset pipeline4m 49s
-
Stylesheets12m 1s
-
JavaScript7m 33s
-
Images6m 22s
-
-
11. Forms
-
Form helpers8m 35s
-
Form options helpers8m 45s
-
Date and time form helpers6m 16s
-
Form errors7m 36s
-
-
12. Data Validation
-
Validation methods11m 37s
-
Write validations12m 7s
-
Validates method3m 15s
-
Custom validations6m 12s
-
-
13. Controller Features
-
Cookies3m 10s
-
Sessions6m 50s
-
Controller filters10m 45s
-
Logging7m 40s
-
-
14. User Authentication
-
Secure passwords8m 35s
-
Login and logout8m 29s
-
Restrict access7m 36s
-
15. Improve the Simple CMS
-
Challenge: AdminUser CRUD2m 44s
-
Solution: AdminUser CRUD7m 56s
-
Public area10m 35s
-
Public area navigation6m 3s
-
Nesting pages in subjects9m 44s
-
Nesting sections in pages7m 37s
-
Finishing touches3m 30s
-
-
Conclusion
-
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.
CancelTake 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.
Share this video
Embed this video
Video: Partial templates