# Determining which controller to write the code into!

**URL:** <https://www.ruby-forum.com/t/determining-which-controller-to-write-the-code-into/150605>\
**Category:** Rails\
**Created:** [October 10, 2008, 11:35am UTC](https://www.ruby-forum.com/t/determining-which-controller-to-write-the-code-into/150605 "2008-10-10T11:35:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chirantan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@chirantan](https://www.ruby-forum.com/u/chirantan)\
**Post date:** [October 10, 2008, 11:35am UTC](https://www.ruby-forum.com/t/determining-which-controller-to-write-the-code-into/150605/1 "2008-10-10T11:35:03Z")

</div>

This question is more about how things work in an MVC architecture  
based ORM application. I want to know which controller to write code  
into when there is a many to many relationship between 2 models.

Example,

I have a model A and model B with respective controllers and have a  
many to many realastionship. I want to list Bs that are associated  
with A in using bridge table. Which controller should the code for  
this go since both are equally related.

Chirantan

---

<div class="post-metadata">

**Author:** ![chirantan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@chirantan](https://www.ruby-forum.com/u/chirantan)\
**Post date:** [October 10, 2008, 3:31pm UTC](https://www.ruby-forum.com/t/determining-which-controller-to-write-the-code-into/150605/2 "2008-10-10T15:31:46Z")

</div>

On Oct 10, 5:34 am, Chirantan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Chirantan

Hi Chirantan. Controller methods generally map to actions that are  
performed on models. So a method named “new” in the User model would  
allow you to create a new User. In other words, if you want to do  
something to ModelA, you’d put the method in ModelA’s controller.

To answer your question, if I wanted to list all Bs associated with a  
particular A, I would probably create a method in the A controller  
called “list\_Bs”.

Hope that helps,  
Nick

---

<div class="post-metadata">

**Author:** ![chirantan](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/eb9ed0/32.png) [@chirantan](https://www.ruby-forum.com/u/chirantan)\
**Post date:** [October 13, 2008, 6:19am UTC](https://www.ruby-forum.com/t/determining-which-controller-to-write-the-code-into/150605/3 "2008-10-13T06:19:17Z")

</div>

Thanks Nick. It helped. I went with the same approach. Thank you for  
your clarification.

Chirantan
