1
我有以下模型創建一個記錄,並添加相關記錄它
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
因此,每個訂單可以有多個產品。
我需要創建一個表單,它允許用戶創建一個訂單幷包含一些產品。對於每種產品,可以設定數量。 我認爲,通過在會話中保留購物車(或購物籃),這個問題的經典解決方案與我的問題不匹配,因爲我需要設置併發送所有材料一次,而不必單擊每個產品的購買按鈕並等待。
是否有任何最佳實踐來實現?