【发布时间】:2013-05-28 07:32:07
【问题描述】:
当我阅读《Agile web development with rails, Task D》一书时,我完全糊涂了。
我知道基类中的 current_cart 方法可以通过会话找到目标购物车。但是,我不知道 sysbol :card_id 来自哪里。
lineItemController调用current_cart方法时,:cart_id的值是多少?
更重要的是,我已经运行了常见的“rails generate scaffold line_item product_id:integer cart_id integer”。这两种cart_id是什么关系?
class ApplicationController < ActionController::Base
protect_from_forgery
private
def current_cart
Cart.find(session[:cart_id])
rescue ActiveRecord::RecordNotFound
cart = Cart.create
session[:cart_id] = cart.id
cart
end
end
【问题讨论】:
-
:card_id只是一个键;一个符号。类似于字符串。这只是稍后在您的会话哈希中识别您的cart.id的一种方式。
标签: ruby-on-rails ruby