This is a common piece of code:
# Template 1
<%= render 'some/partial', magic: variable %>
# Template 2
<%= render 'some/partial' %>
# some/partial
<%= defined?(magic) ? magic : '' %>
That defined?
check is pretty gross. I'd much rather be able to do:
# some/partial
<%= locals[:magic] %>
These fucking Rails people have thought of everything! local_assigns
is exactly this and already available. TIL!
This is actually an kind of private API as it's a local variable eval'ed here. There's an isssue (#15700) to document it. Probably the naming local_assigns
will remain
:facepunch: :horse: brohoof
Most helpful comment
These fucking Rails people have thought of everything!
local_assigns
is exactly this and already available. TIL!