# What happened to my increment\_counter method?

**URL:** <https://www.ruby-forum.com/t/what-happened-to-my-increment-counter-method/58074>\
**Category:** Rails\
**Created:** [April 18, 2006, 7:29am UTC](https://www.ruby-forum.com/t/what-happened-to-my-increment-counter-method/58074 "2006-04-18T07:29:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![travis\_laduke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e95f7d/32.png) [@travis\_laduke](https://www.ruby-forum.com/u/travis_laduke)\
**Post date:** [April 18, 2006, 7:29am UTC](https://www.ruby-forum.com/t/what-happened-to-my-increment-counter-method/58074/1 "2006-04-18T07:29:56Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![travis\_laduke](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e95f7d/32.png) [@travis\_laduke](https://www.ruby-forum.com/u/travis_laduke)\
**Post date:** [April 25, 2006, 8:15pm UTC](https://www.ruby-forum.com/t/what-happened-to-my-increment-counter-method/58074/2 "2006-04-25T20:15:57Z")

</div>

Quoting travis laduke [removed\_email\_address@domain.invalid](mailto: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
