Reputation: 731
I got such a problem - there is a partial and I can not pass a variable there:
in partial I have;
<%= object.title %>
How I pass variables:
<%= render :partial => 'shared/post_preview', :locals => { :object => article } %>
the error I see looks like
**undefined local variable or method `object'**
Any ideas? I tried already everything seems...
also tried:
<%= render :partial => 'shared/post_preview', :object => article %>
<%= render 'shared/post_preview', :object => article %>
<%= render :partial => 'shared/post_preview', :object => article %>
everytime i see the same error...
Upvotes: 4
Views: 2620
Reputation: 2072
Use this:
Assuming you have defined @article instance variable in action.
<%= render 'shared/post_preview', object: @article %>
This must solve your problem.
Upvotes: 3
Reputation: 731
the problem was in the commented code in the partial file. Somehow it was counted like an actual code...
<!--
<div class="row">
<div class="col-lg-6">
<%= render :partial => 'shared/post_preview' %>
<%= render :partial => 'shared/post_preview' %>
</div>
<div class="col-lg-6">
<%= render :partial => 'shared/post_preview' %>
<%= render :partial => 'shared/post_preview' %>
</div>
</div>
-->
Upvotes: 1