Forum: Ruby on Rails Many to many in separate has_one controller

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Dd0ae027091ee9664aa2d177794d01d2?d=identicon&s=25 mark_d (Guest)
on 2009-04-02 00:20
(Received via mailing list)

I have a problem deciding the best way to manage a many_to_many

It define the relationships as so:
## 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][/code]
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.
D93ae163042e0a937941e0ba4d8ed5d7?d=identicon&s=25 Eric (Guest)
on 2009-04-02 01:00
(Received via mailing list)
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.).

Dd0ae027091ee9664aa2d177794d01d2?d=identicon&s=25 mark dixon (Guest)
on 2009-04-02 14:16
(Received via mailing list)
Thanks Eric. That sounds great.

How though would I create a form_for on a relation table. There is no
object, or fields of an object.
This topic is locked and can not be replied to.