Forum: Ruby on Rails what happened to my increment_counter method?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
travis laduke (Guest)
on 2006-04-18 09:29
(Received via mailing list)
this used to work for me. i started re-writing my little app and now
it doesn't work.

here's my models:
class Company < ActiveRecord::Base
   has_many :people
end
class Person < ActiveRecord::Base
   belongs_to :Company, :counter_cache => true
end

then i go into my console and say:
c = Company.find(:first)
c.increment_counter

and its all like "waaaaaaH"
NoMethodError: undefined method `increment_counter' for #<Company:
0x259e3b0>
         from /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.14.2/
lib/active_record/base.rb:1792:in `method_missing'
         from (irb):8


if i type:
Company.inc and then hit tab, .increment_counter shows up.

i'm confused.
Rails 1.1.2
i do have a people_count column in my company table

zuh?
Jeffrey L. Taylor (Guest)
on 2006-04-25 22:15
(Received via mailing list)
Quoting travis laduke <removed_email_address@domain.invalid>:
>
> then i go into my console and say:
> c = Company.find(:first)
> c.increment_counter

You have to say which counter!  A class can have more than one.  But,
that is probably a bad idea.  You should use the proper Rails idiom
and let the code handle it:

c = Company.find(:first)
c.people.create(...

Jeffrey
This topic is locked and can not be replied to.