创建记录并向其添加关联记录
我有一个以下模型
class Order < ActiveRecord::Base
has_many :products, :through => :line_items
end
class Product < ActiveRecord::Base
belongs_to :order
end
line_items 是一个表,它将订单与多个产品相关联。
create_table "line_items", :force => true do |t|
t.integer "order_id"
t.integer "product_id"
t.integer "count"
t.datetime "created_at"
t.datetime "updated_at"
end
因此,每个订单可以有多个产品。
我需要创建一个表单,允许用户创建订单并在其中包含一些产品。对于每种产品,可以设置数量。 我认为,这个问题的经典解决方案,通过保持购物车(或购物篮)在会话中,不符合我的问题,因为我需要设置并发送所有的东西一次,而不是点击每个产品的购买按钮并等待。
是否有任何最佳实践来实现这一点?
I have a following model
class Order < ActiveRecord::Base
has_many :products, :through => :line_items
end
class Product < ActiveRecord::Base
belongs_to :order
end
line_items is a table, that associates an Order with multiple products.
create_table "line_items", :force => true do |t|
t.integer "order_id"
t.integer "product_id"
t.integer "count"
t.datetime "created_at"
t.datetime "updated_at"
end
So, each order can have multilple products.
I need to create a form, that allows user to create an order and to include some products to it. For each product, the quantity can be setted.
I think, the classic solution of this problem, via keeping a cart (or basket) in session, not matches my problem, because i need to setup and send all the stuff once, without clicking on each product's buy button and waiting.
Are there any best practices to implement this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看这两个:
Check out these two: