freshest
freshest

Reputation: 6241

Ruby on Rails - Create an order from a quote

I have a simple application to calculate a quote for a picture framing job. The user enters all the data into a form and then the application works out the quote based on this data.

The user is then asked if they want to create an order out of this quote, if they do then the user selects or enters a new customer to associate this order with, and the application creates the order.

What is the best way to do this in Ruby on Rails, do I store the form data into a session and then use this session to create the order if the user decides to create an order from the quote?

Here is the the relevant schema:

create_table "orders", :force => true do |t|
  t.string   "status"
  t.integer  "customer_id"
  t.datetime "created_at"
  t.datetime "updated_at"
end

create_table "order_items", :force => true do |t|
  t.integer "order_id"
  t.integer "height"
  t.integer "width"
  t.string  "mount"
  t.integer "mount_width"
  t.string  "moulding_1"
  t.string  "moulding_2"
  t.string  "moulding_3"
  t.boolean "glass"
  t.boolean "backing_board"
end

create_table "customers", :force => true do |t|
  t.string   "name"
  t.string   "address"
  t.string   "tel_number"
  t.string   "email_address"
  t.datetime "created_at"
  t.datetime "updated_at"
end

Upvotes: 0

Views: 749

Answers (3)

Aaron Scruggs
Aaron Scruggs

Reputation: 712

The preferred way to store session data in RoR is in a cookie store. The cookie store is not very large. For that reason, you probably wouldn't want to try to store a lot of data in the session.

Consider allowing customer_id on orders to be nullable. Then you could store in the cookie store a hash like ":order_id => " . This would allow you to remember what the anonymous user had selected even if they leave the site and come back. This is also great for being able to measure your attrition rate during the signup process (how many people got a quote then never came back).

The challenge with not storing this information in the database is that it could allow the user to manipulate this data after they have entered it. This would be bad if you quoted them a price and left it on the page.

Upvotes: 0

Matt
Matt

Reputation: 5398

I wouldn't create any object from the quote at all.

I'd create a different action for calculating the quote and then probably use ajax to call that every time some form field value changed. A separate button and a separate action would create order out of the form directly.

Upvotes: 1

Max Williams
Max Williams

Reputation: 32933

Don't use the session for anything other than which user is logged in at the moment on a given browser. Think of the session as a convenience but don't use it for anything critical, that would really matter if it got lost. Also, bear in mind that rails is stateless, ie doesn't carry anything in memory from one request to the next.

I would just make a form to make an order on the page that shows the quote data, and stuff the relevant fields with the data from the quote, such as how much it is, what order item is involved, or whatever.

Upvotes: 0

Related Questions