I’ve been googling around about this and can’t find the right path. I’m working on a Rails app that is using a method called local_assigns. This appears to be something in Rails or a gem, and not specific to my app, but it’s used for rendering a partial in different contexts, such as this:
<% if local_assigns[:custom_name] %>
<li><%= custom_name %></li>
<% else %>
or also this:
<%= render "discussions/complementary/#{local_assigns[:action] || params[:action]}" %>
Is this is Rails method? Where can I find more documentation about this?
local_assignsis a Rails view helper method that you can check whether this partial has been provided with local variables or not.Here you render a partial with some values, the
headlineandpersonwill become accessible with predefined value.In
shared/headerview:Here is how you check these variables has passed in or not:
Check this document for more detail on the section rails 3.2 Passing local variables to sub templates.
Updated rails 7 link: ActionView/Base.html