创建一个记录,并添加相关记录它
问题描述:
我有以下模型创建一个记录,并添加相关记录它
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
因此,每个订单可以有多个产品。
我需要创建一个表单,它允许用户创建一个订单并包含一些产品。对于每种产品,可以设定数量。 我认为,通过在会话中保留购物车(或购物篮),这个问题的经典解决方案与我的问题不匹配,因为我需要设置并发送所有材料一次,而不必单击每个产品的购买按钮并等待。
是否有任何最佳实践来实现?