[英]shopping cart ruby on rails
im using 我正在使用
def add_to_cart
@cart = find_cart
product = Product.find(params[:id])
@cart.add_product(product)
end
from a book. 从一本书。 this is to create a shopping cart.
这是创建一个购物车。 what I don't understand is, do I need a controller for my cart?
我不明白的是,我的购物车需要控制器吗? because without it,its giving me an error
因为没有它,它给我一个错误
I get the feeling you're not really sure how to use Rails. 我感到您不太确定如何使用Rails。
Whether or not you need a controller for you cart is up to you, however I would have one. 您是否需要为购物车配备控制器取决于您,但是我有一个。 That way you can have a "view your cart" page, as well as easily delete items.
这样,您可以拥有“查看购物车”页面,并轻松删除项目。
原则上,除非你有一个路由,你不应该需要一个控制器Carts
你的config / routes.rb文件内。
Yes, the above method should definitely live inside a controller. 是的,上述方法肯定应该存在于控制器内部。 The controller should look like this:
控制器应如下所示:
http://media.pragprog.com/titles/rails2/code/depot_f/app/controllers/store_controller.rb http://media.pragprog.com/titles/rails2/code/depot_f/app/controllers/store_controller.rb
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.