TIL: Template Strict Locals (TSL)
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:anduser_group:are required.last_signed_in:is optional with a default value ofnil.
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.