I think I''ve got the answer:
def signup
@user = User.new(@params[:user])
@user.company = Company.new(@params[:company])
@user.address = Address.new(@params[:address])
if @request.post? and @user.valid?
User.transaction do
@user.save
#return
@user.company.addresses << @user.address
end
flash[:notice] = ''Signup successful''
redirect_to :action => ''welcome'', :user => @user
else
flash.now[:notice] = ''Signup failed''
end
end
In the log:
BEGIN
INSERT INTO companies (`name`) VALUES (''acme'')
INSERT INTO addresses (`company_id`, `street`) VALUES (NULL, ''Smith
Street'')
INSERT INTO users (`name`, `address_id`, `company_id`) VALUES VALUES
(''John'', 13, 8)
SELECT * FROM addresses WHERE addresses.company_id = 8
37mUPDATE addresses SET `street` = ''Dunkerstr'', `company_id` =
8 WHERE
id = 13
COMMIT
Did a rudimentary test (uncommented ''return'') and nothing was
committed.
--
Posted via http://www.ruby-forum.com/.