From the course: Ruby on Rails 5 Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Partial templates

Partial templates - Ruby on Rails Tutorial

From the course: Ruby on Rails 5 Essential Training

Start my 1-month free trial

Partial templates

- [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…

Contents