Search code examples
variablesruby-on-rails-5renderpartial

Can not pass variables to partial (Rails5)


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


Solution

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