I suspect there is a standard way to handle this issue but I haven't
found it.

In my controller create action I have a Transaction.  Lets say I'm
creating a user object here.

def new
  User.transaction do
      @user = User.new(params[:user])
     #do some stuff  set success if no rollback
  end
  if success
   goto success page
  else
    render :action => :new
  end
end

Now the problem here is when new is rendered @user has an id and it
treats it as an edit instead of a new.

I could do a the following in the fail block
@user = User.new(params[:user])
render :action => :new

but the errors are lost (and any changes or associations i created)

Or I could nil out the id
@user.id = nil
render :action => :new

It would be nice if the rollback did this for me (sort of like Object
Transactions used to but without wiping out the errors and other
information)?  In my case User has many addresses and many orders so I
also need to check and nil their IDs.  yuck.

What's the best practice here?

Tony

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to