Following just a quick look at the code see below for some obvious issues. On 12 March 2010 19:43, Martin Colwell <[email protected]> wrote: > I'm definitely a noob to rails so sorry if this is trivial. I have > tables with associations on them. The associations are supposed to add > methods to my models like model.others and model.others= and so on but > when I try to use them I get errors like the following. > > NoMethodError: undefined method `states' for #<Ad:0x2c8a88c> > from > C:/Ruby/lib/ruby/gems/1.8/gems/activerecord-2.3.5/lib/active_record/attribute_methods.rb:260:in > `method_missing' > from (irb):4 > > I've followed the execution in the debugger and all that the > method_missing seems to do is generate setters, getters and ? for the > fields in the table, it doesn't seem to generate or look for any of the > methods that > http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html > says it should. I only did this once though and I didn't really > understand what I was reading > > My code is the following > > Model classes: > > file: app/models/ad.rb > class Ad < ActiveRecord::Base > belongs_to :customer > has_and_belongs_to_many :state
That should be :states (plural) > end > > file: app/models/state.rb > class State < ActiveRecord::Base > has_and_belongs_to_many :ad Should be :ads > has_many :zip_code :zip_codes > has_many :town :towns Colin -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

