'Rails locals in nested partials
I have an index.html.erb file with this line:
<%= render partial: 'shared/object_grid', locals: { items: @cars, item_type: 'Car', show_versions: true } %>
I then have an object_grid partial like so:
<div class="object-grid" data-object="<%= item_type.downcase %>" data-infinitescroll-target="grid">
<%= render partial: "#{item_type.downcase.pluralize}/#{item_type.to_s.downcase}", collection: items, locals: { show_versions: show_versions } %>
</div>
I then have a car partial that does some output but importantly has the following conditional in it:
<% if car.has_versions? && show_versions %>
// Show version details here
<% end %>
The area where the version details should be showing is not being output.
The object_grid partial has the following error:
_object_grid.html.erb where line #2 raised:
undefined local variable or method `show_versions' for #ActionView::Base:0x000000006d4d40
Any ideas?
If I do <%= show_versions %> above the render partial line in object_grid then I see the output of "true", but it fails on the render line.
I'm really confused.
Can you please help?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
