我正在关注本指南, http://www.2dconcept.com/ jquery-grid-rails-plugin ,用于设置示例jQuery数据网格。

一切似乎都很好,但是当我去 http://127.0.0.1:3000/users ,我明白了:

 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>

关于我做错了什么的想法?

有帮助吗?

解决方案

我没有使用过jqGrid,但示例代码是设置 users 而你正在访问 @users - 我不确定你的错误是不是部分或教程。

其他提示

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

并确保@users不是零。

我已经使用Rails 4.0创建了示例应用程序jqgrid,看看它。

希望你会喜欢这个,找到以下链接 -

https://github.com/Rameshwar007/jqgrid_rails_4_sample

感谢

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top