Everything was good until the establishment of the relation. I am
unable to go any further than "Linking Models Together" : I can create
the "vendors" mentionned in the exemple, and I can get an "event" to
look to. But when I try to create an "expense", I get a message
saying :
NoMethodError: undefined method `expenses' for #<Event:0x125e008>
from /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/
attribute_methods.rb:205:in `method_missing'
from (irb):2
Could anybody help me ? I have checked the classes files, everything
seems according to the article. I did checks on the database, the
table "expenses" has been created but is empty. The "id" fiels are
present in each of the tables... I don't see where to look to now.
NoMethodError: undefined method `expenses' for #<Event:0x125e008>
from /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/
attribute_methods.rb:205:in `method_missing'
from (irb):2
Could anybody help me ? I have checked the classes files, everything
seems according to the article. I did checks on the database, the
table "expenses" has been created but is empty. The "id" fiels are
present in each of the tables... I don't see where to look to now.
Do you have the following in your Event class:
has_many :expenses
?
This is the line that give the Event class the method "expenses" which
links to the Expense class. And in the Expense class:
belongs_to :event
to get the map the other way around giving the Expense class the method
"event".
Yes. Was the error produced in a console that you started *after* making
the extra changes to the Event and Expense models? In a console, the
models are loaded when first used only and if you change them then you
need to reload them. You can do this with:
reload!
or just by restarting the console (use "quit" to exit, then run the
console again).
NoMethodError: undefined method `expenses' for #<Event:0x125dd88>
from /Library/Ruby/Gems/1.8/gems/activerecord-2.0.2/lib/active_record/
attribute_methods.rb:205:in `method_missing'
from (irb):2
In fact, I have been fooled by XCode that does not save the files when
it tells you that it does... I had to close completely XCode for some
modifications to be taken into account by rails. I have noticed this
when I had to restart my computer (battery low), my files where in an
old version. When I retyped the missing code I made typos, and I saw
them appear in the logs. The only solution to correct them has been to
close completely XCode and to execute a reload! in the console... A
bit strange.
Thanks to all and sorry for your time,
I had this exact same problem. Found this page searching for a
solution to my "NoMethodError" blues. Had to close XCode and re-open
it for the changes to be recognized. That is a VERY annoying
problem.
Also had to quit the ruby console and restart it. Using the "reload!"
command mentioned above did not work.