views:

26

answers:

1

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 ?