# My controller became fat trying to handle multiple models -

**URL:** <https://www.ruby-forum.com/t/my-controller-became-fat-trying-to-handle-multiple-models/114040>\
**Category:** Rails\
**Created:** [September 7, 2007, 9:09am UTC](https://www.ruby-forum.com/t/my-controller-became-fat-trying-to-handle-multiple-models/114040 "2007-09-07T09:09:07Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris\_johnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ac91a4/32.png) [@chris\_johnson](https://www.ruby-forum.com/u/chris_johnson)\
**Post date:** [September 7, 2007, 9:09am UTC](https://www.ruby-forum.com/t/my-controller-became-fat-trying-to-handle-multiple-models/114040/1 "2007-09-07T09:09:07Z")

</div>

Hello all.

I am experiencing something that has to be fairly common in the rails  
world, but I haven’t found a clean solution yet.

I have a SignupController that handles multiple models in a single  
form.  
Those models are User, UserProfile, CreditCard, Subscription, and  
Order.  
When the form is filled out and posted, I want to do exactly what I  
would do if the form was only for a single model:  
(1) Build the object from params[:model]  
(2) Save the object, rendering errors to the form page if they exists  
(otherwise flash ‘Success’).

Why is this so tough when dealing with multiple models? Here is what  
I  
am doing (and this is how I know it’s too complicated and there must  
be  
a better way):  
(1) Building each object (@user = User.new(params[:user]), @cc =  
CreditCard.new(params[:cc]), etc).  
(2) [Parked at Loopia](http://pastie.caboo.se/94819)  
(3) I haven’t gotten to manually building an ‘errors’ hash yet.

I would love to hear some feedback.  
Many thanks,  
Chris

---

<div class="post-metadata">

**Author:** ![chris\_johnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ac91a4/32.png) [@chris\_johnson](https://www.ruby-forum.com/u/chris_johnson)\
**Post date:** [September 7, 2007, 10:05am UTC](https://www.ruby-forum.com/t/my-controller-became-fat-trying-to-handle-multiple-models/114040/2 "2007-09-07T10:05:12Z")

</div>

On 07 Sep 2007, at 09:08, chris johnson wrote:

> (2) Save the object, rendering errors to the form page if they exists  
> (3) I haven’t gotten to manually building an ‘errors’ hash yet.  
> Seems all of other the models are related to the User model, you  
> should look into validates\_associated:

[http://rails.rubyonrails.com/classes/ActiveRecord/Validations/](http://rails.rubyonrails.com/classes/ActiveRecord/Validations/)  
ClassMethods.html#M000948

Best regards

Peter De Berdt
