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

On 14 Jan 2008, at 14:59, Kad K. wrote:

or should I use a transaction with rollback ?o
or
use validates_associated …

foo.valid? ?

Fred

On Jan 14, 2008, at 3:59 PM, Kad K. 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs