Hey
I’m having the worst time with 1 block of my app lol.
I have an address model with many validations.
I run this code on a 4 model form. If the params for the adresses are
blank (not valid) or just not valid the objects should not be created
and neither should the user or dealer. But both the user and dealer
are being saved and the addresses are throwing no validation errors. I
know the model is valid as i’ve unit tested it thoroughly. Why are the
validations not being processed on create. I’ve read the differences
for new-vs-create-vs-build but it sounds like build associations
should run validations.
ActiveRecord::Base.transaction do
params[:mailing_address] ||= []
params[:billing_address] ||= []
@dealer = Dealer.new(params[:dealer])
@dealer.save!
@user = @dealer.users.new(params[:user])
@user.roles << Role.find(3)
@user.save!
@dealer.addresses.create(params[:mailing_address])
@dealer.addresses.create(params[:billing_address])
end
cheers,
brianp