Kad Kerforn
2008-Jan-14 14:59 UTC
validating linked ActiveRecords without saving them in DB
I would like to create new records @user = User.new(params[:user]) @activity = Activity.new(params[:activity]) .... then validating them without saving to the DB... (as saving one depend upon saving others..) or should I use a transaction with rollback ?o or use validates_associated .. or both .. or ? thanks kad -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jan-14 15:22 UTC
Re: validating linked ActiveRecords without saving them in DB
On 14 Jan 2008, at 14:59, Kad Kerforn wrote:> > I would like to create new records > > @user = User.new(params[:user]) > @activity = Activity.new(params[:activity]) > .... > > then validating them without saving to the DB... (as saving one depend > upon saving others..) > > or should I use a transaction with rollback ?o > or > use validates_associated .. >foo.valid? ? Fred> or both .. or ? > > thanks > > kad > -- > Posted via http://www.ruby-forum.com/. > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Xavier Noria
2008-Jan-14 15:34 UTC
Re: validating linked ActiveRecords without saving them in DB
On Jan 14, 2008, at 3:59 PM, Kad Kerforn wrote:> @user = User.new(params[:user]) > @activity = Activity.new(params[:activity]) > .... > > then validating them without saving to the DB... (as saving one depend > upon saving others..) > > or should I use a transaction with rollback ?o > or > use validates_associated ..User validates_associated :activity. @user = User.new(params[:user]) @user.build_activity(params[:activity]) if @user.save # saves both, runs in a transaction ... end -- fxn --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---