注册
登录
统计
帮助
RailsChina.com
»
Ruby on Rails
» 有关You have a nil object when you didn't expect it!请教
‹‹ 上一主题
|
下一主题 ››
发新话题
发布投票
发布商品
发布悬赏
发布活动
发布辩论
发布视频
打印
有关You have a nil object when you didn't expect it!请教
max888
新手上路
个人空间
发短消息
加为好友
当前离线
1
#
大
中
小
发表于 2008-7-19 10:52
只看该作者
有关You have a nil object when you didn't expect it!请教
学AWDWR第二版第九章Ajzx时,想迁移购物车,但出现以下问题,google了好久都没找到答案,望指教。
NoMethodError in Store#index
Showing app/views/store/_cart_item.rhtml where line #2 raised:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.quantity
Extracted source (around line #2):
1: <tr>
2: <td><%= cart_item.quantity %> & times; </td>
3: <td><%= h(cart_item.title) %></td>
4: <td class="item-price" ><%= number_to_currency (cart_item.price) %></td>
5: </tr>
Trace of template inclusion: /app/views/store/_cart.rhtml, /app/views/layouts/store.rhtml
RAILS_ROOT: ./script/../config/..
Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/views/store/_cart_item.rhtml:2:in `_run_rhtml_47app47views47store47_cart_item46rhtml'
#{RAILS_ROOT}/app/views/store/_cart.rhtml:3:in `_run_rhtml_47app47views47store47_cart46rhtml'
#{RAILS_ROOT}/app/views/layouts/store.rhtml:15:in `_run_rhtml_47app47views47layouts47store46rhtml'
ps:用 rake db:sessions:clear 清理session也不行。
UID
115
帖子
9
精华
0
积分
127
阅读权限
10
在线时间
5 小时
注册时间
2007-1-28
最后登录
2008-7-19
查看详细资料
TOP
alan874
Alan
中级会员
个人空间
发短消息
加为好友
当前离线
2
#
大
中
小
发表于 2008-7-19 11:28
只看该作者
cart_item对象为nil
请检查下
然后就是
_cart_item.rhtml
应该是你render进来的吧 检查传入参数是否正确
复制内容到剪贴板
代码:
:collection =>? 或者 :object =>?
PS:我没有看你那个书 只是看着你上面的错误提示猜的
UID
1094
帖子
56
精华
0
积分
240
阅读权限
30
在线时间
23 小时
注册时间
2008-5-7
最后登录
2008-10-8
查看详细资料
TOP
max888
新手上路
个人空间
发短消息
加为好友
当前离线
3
#
大
中
小
发表于 2008-7-19 11:33
只看该作者
谢谢了 弄好了
UID
115
帖子
9
精华
0
积分
127
阅读权限
10
在线时间
5 小时
注册时间
2007-1-28
最后登录
2008-7-19
查看详细资料
TOP
‹‹ 上一主题
|
下一主题 ››
== 站内业务区 ==
主机业务咨询
== 技术讨论区 ==
Ruby on Rails
Web开发
开发工具
部署与调优
社区资讯
== IT生活区 ==
招聘与合作
休闲小屋