Forum: Ruby on Rails Is it time for transactions yet?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Efe398b3b5436b0a8d4430090e8f86ea?d=identicon&s=25 subimage (Guest)
on 2005-11-29 11:58
(Received via mailing list)
I've started on my second rails project, one which is a little more
complex
than my first.

In this, I've designed a DB to handle orders from an online store. My
orders
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
time to
start.

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
it
real quickly and tell me what I'm doing wrong? I'm only getting
@order_user
saved, when I thought all the associated records should be persisted as
well...

Here's the code:
----------
  # Creates an order from new.
  def create
    @order_user = OrderUser.new(params[:order_user])

    @order = @order_user.orders.new(params[:order])

    @billing_address =
@order_user.order_addresses.new(params[:billing_address])

    if params[:use_separate_shipping_address] then
      @shipping_address =
@order_user.order_addresses.new(params[:shipping_address])
    else
      # 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"
view
      @shipping_address = OrderAddress.new(params[:shipping_address])
    end

    @order_account =
@order_user.order_accounts.new(params[:order_account])

    # Transaction support here?
    if @order_user.save!
      flash[:notice] = 'Order was successfully created.'
      redirect_to :action => 'list'
    else
      render :action => 'new'
    end
  end


As always, many thanks in advance...
This topic is locked and can not be replied to.