# Many to many in separate has\_one controller

**URL:** <https://www.ruby-forum.com/t/many-to-many-in-separate-has-one-controller/164505>\
**Category:** Rails\
**Created:** [April 2, 2009, 12:20am UTC](https://www.ruby-forum.com/t/many-to-many-in-separate-has-one-controller/164505 "2009-04-02T00:20:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mark\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@mark\_d](https://www.ruby-forum.com/u/mark_d)\
**Post date:** [April 2, 2009, 12:20am UTC](https://www.ruby-forum.com/t/many-to-many-in-separate-has-one-controller/164505/1 "2009-04-02T00:20:51Z")

</div>

Hi.

I have a problem deciding the best way to manage a many\_to\_many  
relationship.

It define the relationships as so:

[code]

## models

# student model

student has\_many subjects :through =\> :enrollments

# subject model

subject has\_many students :through =\> :enrollments

# enrollments model

belongs\_to :student  
belongs\_to :subject[/code]  
How can I have a separate controller to manage a students enrollments  
from one page? Imagine a student page with radio buttons defining  
their relationship with a subject, something like [enrolled, deferred,  
cancelled] for example. This would surely be a one\_to\_one relationship  
from a routing perspective. My idea was to define this extra  
controller but I’m quickly thinking I’m going the wrong way with this.

`
map.resources :student, :has_one => :curriculum, :except =>
[:new, :create]`  
Within the controller and the view, what would the form\_for be for?  
There is no curriculum model, and I can’t have a form\_for a  
relationship (can I?).

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![mark\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@mark\_d](https://www.ruby-forum.com/u/mark_d)\
**Post date:** [April 2, 2009, 1:00am UTC](https://www.ruby-forum.com/t/many-to-many-in-separate-has-one-controller/164505/2 "2009-04-02T01:00:41Z")

</div>

This is part of what has\_many :through is for. You already have an  
enrollments model, so you can just create a controller for it, adding  
extra attributes where necessary (cancelled, etc.).

-eric

---

<div class="post-metadata">

**Author:** ![mark\_d](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/48db29/32.png) [@mark\_d](https://www.ruby-forum.com/u/mark_d)\
**Post date:** [April 2, 2009, 2:16pm UTC](https://www.ruby-forum.com/t/many-to-many-in-separate-has-one-controller/164505/3 "2009-04-02T14:16:23Z")

</div>

Thanks Eric. That sounds great.

How though would I create a form\_for on a relation table. There is no  
actual  
object, or fields of an object.
