Hi, I have the following models: class Contact < ActiveRecord::Base has_many :contact_lists, :dependent => true has_many :lists, :through => :contact_lists end class List < ActiveRecord::Base has_many :contact_lists, :dependent => true has_many :contacts, :through => :contact_lists end class Contact_List < ActiveRecord::Base belongs_to :lists belongs_to :contacts end I included a validates_presence_of :list_id, :contact_id in Contact_List, but I am getting a nil.collection error when I submit without any values. Any ideas? Also, can I use validates_uniqueness_of :list_id, :contact_id to prevent duplicate records from being added to Contact_List? Thanks, David -- 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 -~----------~----~----~----~------~----~------~--~---
Vishnu Gopal
2006-Sep-30 04:34 UTC
Re: Problem with validates_presence_of in linking table
Try validates_presence_of :list, :contact validates_uniqueness should work. And it''s belongs_to :list; belongs_to :contact (singular) Vish On 9/30/06, David Lelong <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi, > > I have the following models: > > class Contact < ActiveRecord::Base > has_many :contact_lists, :dependent => true > has_many :lists, :through => :contact_lists > end > > class List < ActiveRecord::Base > has_many :contact_lists, :dependent => true > has_many :contacts, :through => :contact_lists > end > > class Contact_List < ActiveRecord::Base > belongs_to :lists > belongs_to :contacts > end > > I included a validates_presence_of :list_id, :contact_id in > Contact_List, but I am getting a nil.collection error when I submit > without any values. Any ideas? > > Also, can I use validates_uniqueness_of :list_id, :contact_id to prevent > duplicate records from being added to Contact_List? > > Thanks, > > David > > -- > 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 -~----------~----~----~----~------~----~------~--~---