agile rails第3版的小陷阱

看agile rails第3版开始一步一步尝试,结果做到购物车时保错:
 NoMethodError in Store#add_to_cart

Showing app/views/store/add_to_cart.rhtml where line #4 raised:

You have a nil object when you didn't expect it!
The error occurred while evaluating nil.items

搞得我一头雾水,后来搞到源代码,又上网查了下原来是这个问题:
就是index方法和add_to_cart两段代码的顺序而已!颠倒顺序试试看,果真又出错,
改过来就好了。问题明白了,本该顺序应该不影响,但关键add_to_cart前面有个private!
费了我不少时间,不知道在rails下有好的日志或调试工具没

你可能感兴趣的:(Rails)