No, this is not a real Sinatra error :).
This is the personal homepage of Elad Meidar, a web developer and an entrepreneur specializing in Ruby on Rails. I hang around in Israel, and i am currently having the best time of my life over at Fiverr.com
I am a proud member of RailsBridge, Helping new Rails developers get into our world and also contributed a few Patches to the Ruby on Rails core.
My current project consists over a simple type of a price quotation system, the user owns parts or products for that matter, and creates a quote for who ever requests one.
i created 3 models
accepts_nested_attributes_for :quote_items and QuoteItem
On the QuoteItem model, i added a before_create callback that will initializes/updates the associated QuotePart instance:
self.quote_part.update_attributes(:pn => self.pn, :condition_id => self.condition_id)
self.build_quote_part(:pn => self.pn, :condition_id => self.condition_id)
*QuoteItem*’s tests passed, proving that the associated QuotePart is being created when creating a new QuoteItem, but the IncomingQuotesControllerTest#create tests failed, cause no QuoteItem was created.
After making sure it’s not a Factory/test syntax error, i tried manually to create a new IncomingQuote and see what is going on, and found out that:
I added some debug prints to make sure that there are no validation errors on the initialization of the QuotePart, and indeed there were none.
i added a
after_create callback to QuoteItem, and checked if the associated QuotePart was created and saved, i found that it was indeed initialized, but was not saved! (
new_record? => true).
I don’t know yet, i think it has something to do with the fact that i am saving 3 levels of initialized associations (IncomingQuote builds QuoteItem that each of them builds QuotePart) and that for some reason the 2nd level association (QuoteItem), is not saving the initialized associations while being saved on it’s own.
i simply added an
after_create callback on QuoteItem to ensure that the associated QuotePart is saved.
if self.quote_part.present? && self.quote_part.new_record?
Not the cleanest way to do it, but it works. Probably will head on it on the next Bugmash.
You're seeing this error because I think it is funny.