TIL: Template Strict Locals (TSL)

Published: (February 13, 2026 at 04:22 AM EST)
1 min read
Source: Dev.to

Source: Dev.to

Template Strict Locals (TSL)

The other day I was reviewing Chris Oliver’s “Powerful Rails Features You Might Not Know” presentation. Among the many useful tips (date and time helpers, etc.) was a particular gem – Template Strict Locals.

Old way

Previously I would leave comments like this in view partials to remind myself which locals were required:

New way – enforced locals

With Template Strict Locals you can use a magic comment that actually enforces the locals:

  • user: and user_group: are required.
  • last_signed_in: is optional with a default value of nil.

Optional locals

You can make a local optional by providing a default value:

No locals allowed

If a partial must not receive any locals, declare an empty list:

Title credit to Chris Oliver.

0 views
Back to Blog

Related posts

Read more »

snip - Terminal Snippet Manager

What I Built snip is a CLI snippet manager that lets developers save, search, and safely execute code snippets directly from the terminal—with fuzzy search, a...