Intern Track Roadmap

Rails helpers: image_tag

This course covers image_tag, the Rails helper that generates an <img> tag from Ruby. It starts with the one required argument, a filename, and the self-closing tag it returns. It explains the fingerprinted src that Propshaft builds from a hash of the file's content, and why that helps browser caching. It shows alt, width, height and loading passing through the options hash. It also looks briefly at an Active Storage variant as the source and checks each output against a temporary image file.

What you'll learn

  • ✓How image_tag turns one filename into a self-closing <img> tag
  • ✓Where the fingerprinted src comes from in Propshaft
  • ✓Why content-based filenames let browsers cache images safely
  • ✓Passing alt, width, height and loading through the options hash
  • ✓How image_tag accepts an Active Storage variant as its source
  • ✓Why a missing file raises Propshaft::MissingAssetError
Free preview · Lesson 1 2 min read

From <img> to image_tag

Lesson 4 of Links and images, on the anatomy of <img>, covered src, alt, width, height and loading, then showed this line near the end without stopping on it:

Read the full lesson free →

Curriculum

7 lessons
Type to start searching...