0

Right now I have a rails partial that looks like this:

<%= render :partial => "/talk/partials/comment", :collection => @comments, :locals => {:votes => @votes} %>

I am passing in a collection of comments and another local variable.

That comment partial then goes right into using the comment variable and works fine.

I have since made another partial called '/talk/partials/comment_2014'. When I try this, I am getting the error undefined local variable or method 'comment'. From what I can gather, when I have a different partial name, something with the variable also changes. I would like to keep the same comment variable for the new partial ''/talk/partials/comment_2014'. How would I go about doing this?

Something I tried which did not work was the following:

<% @comments.each do |comment| %>
  <%= render :partial => "/talk/partials/comment_2014", comment: comment, :locals => {:votes => @votes} %>
<% end %>

which did not work either.

1 Answer 1

1

You can do it this way

<% @comments.each do |comment| %>
  <%= render "/talk/partials/comment_2014", comment: comment, votes: @votes %>
<% end %>

Or

<% @comments.each do |comment| %>
  <%= render partial: "/talk/partials/comment_2014", locals: { comment: comment, votes: @votes } %>
<% end %>

Notice in the second way the comment is inside the locals.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.