Rails associations question

I have two models:

Post:
has_many :votes

Vote:
belongs_to :post

when i do:

v = Vote.find(1)

I can access all the post information.

If I get a post, howerver:

p = Post.find(1)

And try to get the votes:

total = p.votes.count

I get an undefined method error.

The foreign keys are correct, and I can't seem to figure this out.

Basically what I need is to be able to do:

p.votes.count

But instead of an amount, I get this:

NoMethodError: undefined method `votes' for #<Post:0x4b2e7c0>
        from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/
active_recor
d/base.rb:1792:in `method_missing'

I can do this:

v.post.title

=> "This is the post title."

So as you can see, I am able to access the post information by
accessing a particular vote, but I can't get all votes for a single
post.

Thoughtware.tv wrote:

Basically what I need is to be able to do:

p.votes.count

But instead of an amount, I get this:

NoMethodError: undefined method `votes' for #<Post:0x4b2e7c0>
        from c:/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/
active_recor
d/base.rb:1792:in `method_missing'

I can do this:

v.post.title

=> "This is the post title."

So as you can see, I am able to access the post information by
accessing a particular vote, but I can't get all votes for a single
post.

In your Post class you need to look carfuly at your 'has_many :votes'
statement. Does it exist? Is ':votes' spelled correctly and is it a
symbol or string?

The error message you are posting has nothing to do with the database
setup, it is is saying that the Model you are using is not set up the
way you think. If this doesn't solve your problem, it would be helpful
to see the relevant code from your Post class.

Its a symbol and it has_many :votes as I sated above, I checked once
again.

I will post the relevant code.