views:

391

answers:

2

I'm following this guide, http://www.2dconcept.com/jquery-grid-rails-plugin, to setup a sample jQuery datagrid.

Everything appears to be good, but when I go to http://127.0.0.1:3000/users, I get this:

 NoMethodError in Users#index

 Showing users/index.html.erb where line #12 raised:

 You have a nil object when you didn't expect it!
 You might have expected an instance of Array.
 The error occurred while evaluating nil.each

 Extracted source (around line #12):

 9:     <th>Role</th>
10:   </tr>
11: 
12: <% for user in @users %>
13:   <tr>
14:     <td><%=h user.pseudo %></td>
15:     <td><%=h user.firstname %></td>

Any ideas as to what I am doing wrong?

Thanks in advance!

+1  A: 

I haven't used jqGrid, but the sample code is setting users and you're accessing @users - I'm not sure if that's an error on your part or the tutorial.

Andy Gaskell
I thought that was the correct syntax to go over through each user in the @users??
NoahD
I think your @users is nil - in the demo he is setting `users` not `@users`
Andy Gaskell
If I switch from @users --> users, I get undefined local variable or method `users' for #<ActionView::Base:0x82bcc50>
NoahD
I would use @users everywhere and make sure that your @users object is actually an array.
Andy Gaskell
A: 

try

<% @users.each do |user| %>
  ...
<% end %>

and be sure that @users isnt nil.

Lichtamberg
I'm fairly sure that @users isn't nil, but still no luck.
NoahD
Please show me your Controller-code and all of the view code..
Lichtamberg