I''m building a simple support ticket system for use in our office. I''ve got a model called Ticket and one called Category and I''m trying to set it up so that I can add categories at will and assign many categories to a single ticket. I''m trying to use the has_many :through association to accomplish this, but I''ve run into an issue. Here''s the basic setup: class Ticket < ActiveRecord::Base has_many :categoryassociations has_many :categories, :through => :categoryassociations end class CategoryAssociation < ActiveRecord::Base has_many :tickets -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
(sorry for the double post, somehow I accidentally prematurely posted part of this....) I''m building a simple support ticket system for use in our office. I''ve got a model called Ticket and one called Category and I''m trying to set it up so that I can add categories at will and assign many categories to a single ticket. I''m trying to use the has_many :through association to accomplish this, but I''ve run into an issue. Here''s the basic setup: class Ticket < ActiveRecord::Base has_many :categoryassociations has_many :categories, :through => :categoryassociations end class CategoryAssociation < ActiveRecord::Base belongs_to :ticket end class Category < ActiveRecord::Base has_many :categoryassociations has_many :tickets, :through => :categoryassociations end I''m now receiving an error "uninitialized constant Ticket::Categoryassociation." I should be able to use @ticket.categories in the view to spit out the associated categories, correct? Does this all look like it should work? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 6 Nov 2007, at 18:39, Coleman Mccormick wrote:> > (sorry for the double post, somehow I accidentally prematurely posted > part of this....) > > I''m building a simple support ticket system for use in our office. > I''ve > got a model called Ticket and one called Category and I''m trying to > set > it up so that I can add categories at will and assign many > categories to > a single ticket. > > I''m trying to use the has_many :through association to accomplish > this, > but I''ve run into an issue. > > Here''s the basic setup: > > class Ticket < ActiveRecord::Base > has_many :categoryassociations > has_many :categories, :through => :categoryassociations > endif you say :categoryassociations, rails assumes your model is Categoryassociation. You need :category_associations for it to look for CategoryAssociation> > > class CategoryAssociation < ActiveRecord::Base > belongs_to :ticket > endthis is missing a belongs_to :category. Fred>--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---