Simply Rails 2 - belongs_to Clause - page 204
I'm following Simply Rails 2 and I am stuck at page 204
I modified the vote.rb file as follows:
Quote:
class Vote < ActiveRecord::Base
belongs_to :story
end
then going over to the console I typed the following command:
Quote:
>> v= Vote.find( :first)
and this was the reply from the console:
Quote:
=> #<Vote id: 1, story_id: 1, created_at: "2009-06-17 19:20:11", updated_at: "2009-06-17 19:20:11">
So far so good. So proceeding to the next step I typed the following command in the console:
and this is the reply from the console:
Quote:
NoMethodError: undefined method 'story' for #<Vote:0x3245524>
from C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/attribute_methods.rb:205:in 'method_missing'
from (irb):9
So using page 162 as a guide (because there was a NoMethodError in Stories#new), the book said the problem is:
Quote:
we haven't declared Story as a resource anywhere.
Again, the book said that:
Quote:
resources in Rails are declared in the file responsible for the Routing Configuration, config/routes.rb
My routes.rb looks like this:
Quote:
ActionController::Routing::Routes.draw do |map|
map.resources :stories
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
So, I tried to add the following line to the routes.db file:
map.resources : votes
And this didn't solve the problem.
So, what exactly is the solution to this problem?
I tried searching for a solution on Google, also on Google blog search. Is there a site that anyone would recommend for information on dealing with Ruby errors?