That's true, that'd take a couple lines out of my code. Another thing I'm looking at is using .save! (inspired by some code I saw by TecnoWeenie) in combination with rescue ActiveRecord::RecordInvalid. Haven't tried yet to see how that plays with the transaction.

.save returns true or flase, while .save! rasies an exception if it fails. Anyone tried using @object.save! with rescue rather than the traditional if @object.save?

On Aug 21, 2006, at 1:31 PM, Stephen Waits wrote:

As long as things are dependent on account.save and user.save, why not just put it all under the one transaction?

@account = Account.new(params[:account])
@user = User.new(params[:user])
Account.transaction do
  if @account.save and @user.save
    @account.users << @user
    # Do something cool
  end
end

--Steve

_______________________________________________
Sdruby mailing list

_______________________________________________
Sdruby mailing list
[email protected]
http://lists.sdruby.com/mailman/listinfo/sdruby

Reply via email to