0

I'm having a problem with a partial that displays takes in a collection of @users, and then creates a report like:

_users.html.erb:

<table>
<tr>
...
</tr>
<% @items.each do |u| %>
..
<% end %>
</table>

So now in my home#index erb page, I want to display 2 reports like:

But I am getting an error saying that items doesn't exist.

undefined method `each' for nil:NilClass

How do I tell the partial that @good_users or @bad_users is to be assigned to @items?

1 Answer 1

1

Use a local variable, like 'users'

<table>
<tr>
...
</tr>
<% users.each do |u| %>
..
<% end %>
</table>

And when you're rendering the partial, set the local variable:

render partial: 'users', locals: { users: @good_users }

or

render partial: 'users', locals: { users: @bad_users }

as appropriate.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.