Insert into database failing

hi all,

i am trying a little project based on the agile book’s shopping cart
example and have hit a problem. the inserts are failing when saving a
quote which contains line_items. the models are as follows
(quote_line_item is using single table inheritance):

class Quote < ActiveRecord::Base
has_many :quote_line_items

class LineItem < ActiveRecord::Base

class QuoteLineItem < LineItem
belongs_to :quote
belongs_to :product

the section of code that actually fails is here (labelled)

def send_quote
@quote =[:quote])
@quote.quote_line_items << @cart.items
if # <---- error occurs here
redirect_to_index(‘Thanks for requesting a quote. We will be in
contact with you shortly’)
redirect_to :action => ‘details’

it fails with the following (note the values to be inserted are actually
objects that have not been dereferenced:

INSERT INTO line_items (order_id, quote_id, updated_at,
created_by, product_id, quantity, type, updated_by,
unit_price, created_at) VALUES(#Quote:0xa75703d0,
#Quote:0xa75738a0, #Quote:0xa75749a8, #Quote:0xa756b268,
#Quote:0xa7561218, #Quote:0xa75632fc, #Quote:0xa7567b18,
#Quote:0xa755ef40, #Quote:0xa7559fcc, #Quote:0xa7553654)

i have debugged the code and immediately before the save the objects
@quote and @cart are correct and without errors. it is a little
confusing. without STI it seems to work fine. i have never received
errors like this before although i have not used STI before.

any suggestions would be greatly appreciated.


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs