I’ve started on my second rails project, one which is a little more
than my first.
In this, I’ve designed a DB to handle orders from an online store. My
are comprised of records that span across 4 tables or so. I’ve not used
transactions to this point in rails, and I’m wondering if now is the
I was under the impression that if I used the syntax below to create my
records they all would be saved at the same time. Can anyone look over
real quickly and tell me what I’m doing wrong? I’m only getting
saved, when I thought all the associated records should be persisted as
Here’s the code:
Creates an order from new.
@order_user = OrderUser.new(params[:order_user])
@order = @order_user.orders.new(params[ :order]) @billing_address =
if params[:use_separate_shipping_address] then @shipping_address =
# Don’t create shipping address as a child of order_user
# Need to re-create it here in case save fails.
# In that case, it needs to be present to display for the “new”
@shipping_address = OrderAddress.new(params[:shipping_address])
# Transaction support here? if @order_user.save! flash[:notice] = 'Order was successfully created.' redirect_to :action => 'list' else render :action => 'new' end
As always, many thanks in advance…