Intern Track Roadmap

ActionView: partials

This course covers ActionView partials: view files written once and rendered wherever the same markup repeats. It uses this project's own files, such as _course_card.html.erb, _form_errors.html.erb and _sponsor_line.html.erb. Lessons explain the leading underscore in partial filenames and how Rails finds them in the calling view's folder. They show how locals are passed, why a missing local raises an error, and how local_assigns handles optional ones. They also cover rendering partials from other folders and comparing the shorthand render form with the explicit one.

What you'll learn

  • ✓What a partial is and why markup is reused through it
  • ✓The underscore naming rule and how Rails locates partial files
  • ✓Passing locals to a partial, including collection: and as:
  • ✓Reading optional locals with local_assigns
  • ✓Rendering a partial from a different folder
  • ✓Choosing between the shorthand and explicit render forms
Free preview · Lesson 1 2 min read

What is a partial?

The roadmap page, app/views/catalog/courses/index.html.erb, renders the same course card for every course: image, title, progress bar and badge, with only the data changing. Writing that markup by hand per course would duplicate twenty-plus lines everywhere a course appears. This project writes it…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...