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. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Basically what I need is to be able to do:>> p.votes.countBut 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. On Feb 7, 1:04 pm, "Thoughtware.TV" <lev...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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.--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
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. -- 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?hl=en -~----------~----~----~----~------~----~------~--~---
Its a symbol and it has_many :votes as I sated above, I checked once again. I will post the relevant code. On Feb 7, 2:52 pm, Starr Trader <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> 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. > -- > Posted viahttp://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?hl=en -~----------~----~----~----~------~----~------~--~---