按照敏捷开发书中做到这个步骤实在不行了。
Showing app/views/store/add_to_cart.html.erb where line #3 raised:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.items
Extracted source (around line #3):
1: <h1>Your Pragmatic Cart</h1>
2: <ul>
3: <% for item in @Cart.items %>
4: <li><%=h (item.title) %></li>
5: <% end %>
6: </ul>
RAILS_ROOT: /root/rubygems/web
Application Trace | Framework Trace | Full Trace
app/views/store/add_to_cart.html.erb:3
Request
Parameters:
{"authenticity_token"=>"a4317573b763d4a8525f2a76762c5d5c74859b84",
"id"=>"14"}
Show session dump
---
flash: !map:ActionController::Flash::FlashHash {}
Response
Headers:
{"cookie"=>[],
"Content-Type"=>"text/html",
"Cache-Control"=>"no-cache"}
[解决办法]
下面两个命令运行过吗?
如果没运行过,就运行第一个。
rake db:sessions:create
如果运行过前一个,就运行一下第二个
rake db:sessions:clear
[解决办法]
@cart 为空,检查你对应的 controller,按书中所写,@cart 是从session中得来的数据,检查下你的session 是不是有内容。是用的什么方式记录的session
[解决办法]