4

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...

Dharam Gollapudi
  • 6,328
  • 2
  • 34
  • 42
Neon_10
  • 711
  • 2
  • 7
  • 19

2 Answers2

3

Use this:

Assuming you have defined @article instance variable in action.

<%= render 'shared/post_preview', object: @article  %>

This must solve your problem.

Pradeep Sapkota
  • 2,041
  • 1
  • 16
  • 30
  • No, the problem was in a commented code contained Ruby and the standard commenting working for html like does not work for Ruby part of code, – Neon_10 Sep 06 '16 at 14:14
1

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>
-->
Neon_10
  • 711
  • 2
  • 7
  • 19