Intern Track Roadmap

ActionView: templates (ERB)

ERB (Embedded Ruby) is an HTML file with small pieces of Ruby inside, and it runs from scratch on every request. This course reads real views from this project, starting with partners.html.erb. It separates the two tags: <%= %> prints a result, and <% %> runs code without output. It shows how a view reads the instance variables its action set, why Rails escapes output by default, and when html_safe overrides that. It then opens an articles#show view and reads lines from the application layout.

What you'll learn

  • ✓What ERB is and how a .html.erb file renders once per request
  • ✓The difference between the <%= %> and <% %> tags
  • ✓Writing conditions and loops in ERB with open, print and close tags
  • ✓How a view reads an action's instance variables, and why unset ones print nothing
  • ✓Default output escaping, cross-site scripting and html_safe
  • ✓How the layout title line and content_for use the same tags
Free preview · Lesson 1 2 min read

What is ERB?

This project's roadmap page, app/views/catalog/courses/index.html.erb, shows "Continue Learning" to someone mid-course and "Start Learning" to someone who hasn't started, through its course card partial, on the same request path. A plain .html file can't do that: every visitor gets the same text.…

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...