# CRUD when saving aggregate objects/calling one controller fr

**URL:** <https://www.ruby-forum.com/t/crud-when-saving-aggregate-objects-calling-one-controller-fr/80321>\
**Category:** Rails\
**Created:** [December 24, 2006, 12:54am UTC](https://www.ruby-forum.com/t/crud-when-saving-aggregate-objects-calling-one-controller-fr/80321 "2006-12-24T00:54:18Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [December 24, 2006, 12:54am UTC](https://www.ruby-forum.com/t/crud-when-saving-aggregate-objects-calling-one-controller-fr/80321/1 "2006-12-24T00:54:18Z")

</div>

My project has a number of objects that aggregate other objects. In  
certain contexts, objects can either be a root object or a child to  
another object.

For example:

Object A can be manipulated on it’s own and has it’s own controller.  
Object B can be manipulated on it’s own and has it’s own controller.  
Object C can be manipulated on it’s own and has it’s own controller.

Object A has many B instances. C can have many instances of B as well.

What is the best way to reuse the save/update code from controller B  
when saving A with B as A’s children?

There are a number of business related actions required when saving B  
that do not seem appropriate for the model

Thanks,  
Dan

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [December 24, 2006, 12:56am UTC](https://www.ruby-forum.com/t/crud-when-saving-aggregate-objects-calling-one-controller-fr/80321/2 "2006-12-24T00:56:21Z")

</div>

On 12/23/06, Dan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> There are a number of business related actions required when saving B  
> that do not seem appropriate for the model

How do you figure? The model is precisely where business-related  
actions should go.

Pat

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [December 24, 2006, 2:30am UTC](https://www.ruby-forum.com/t/crud-when-saving-aggregate-objects-calling-one-controller-fr/80321/3 "2006-12-24T02:30:32Z")

</div>

On 12/23/06, Dan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> they are saved. In otherwords lots of logic. I am pretty new to  
> Rails, but with other MVC platforms I have tried to put most of the  
> this type of functionality into controllers. Wrong application with  
> Rails?

Wrong approach with MVC. Business logic goes in the model. The  
controller is just for coordinating stuff. Jamis B. has a good  
article [1] that ought to shed some light for you.

Pat

[1] [Buckblog: Skinny Controller, Fat Model](http://weblog.jamisbuck.org/2006/10/18/skinny-controller-fat-model)

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [December 24, 2006, 1:12am UTC](https://www.ruby-forum.com/t/crud-when-saving-aggregate-objects-calling-one-controller-fr/80321/4 "2006-12-24T01:12:23Z")

</div>

> > There are a number of business related actions required when  
> > saving B
> 
> > that do not seem appropriate for the modelHow do you figure? The model is precisely where business-related  
> > actions should go.
> 
> Pat

I am creating user tasks, sending notifications, starting long-running  
business processes, auditing, etc based on the state of the objects as  
they are saved. In otherwords lots of logic. I am pretty new to  
Rails, but with other MVC platforms I have tried to put most of the  
this type of functionality into controllers. Wrong application with  
Rails?

Thanks.

---

<div class="post-metadata">

**Author:** ![dan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/eada6e/32.png) [@dan](https://www.ruby-forum.com/u/dan)\
**Post date:** [December 24, 2006, 3:04am UTC](https://www.ruby-forum.com/t/crud-when-saving-aggregate-objects-calling-one-controller-fr/80321/5 "2006-12-24T03:04:38Z")

</div>

Thanks, the link was very helpful.l
