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. [code] 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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Apr 1, 11:38 am, mark_d <darc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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. > [code] > 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.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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. On Wed, Apr 1, 2009 at 11:59 PM, Eric <ericghill-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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 > > On Apr 1, 11:38 am, mark_d <darc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > 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. > > [code] > > 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. > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---