The other day I was giving Chris' "Powerful Rails Features You Might Not Know" presentation a look, and among many useful tips (date and time helpers, nice) was a particular gem - Template Strict Locals.
Up till now I had been leaving comments like this in view partials:
<%# Partial requires `user: @user, group: user_group` %>
But now we have something better, magic comment that will actually enforce the locals!
<%# locals: (user:, user_group:, last_signed_in: nil) -%>
You can also have optional locals with a default value, and even specify a partial that must not be passed any locals:
# group is now optional
<%# locals: (user:, user_group: nil) -%>
# no locals, please
<%# locals: () -%>
Title credit to Chris Oliver.
Top comments (0)