Hello,
I recently set up a rails application, and wanted to provide helper methods in
my model class.
I was confused that the class DOESN''T refer to its fields as instance
variables. I merely had to
type in the field names to be able to work with their data.
Here''s an example:
I have a "Chessgame" class with a begindate and an enddate. To get
the number of hours that the
game took, I wrote an "hours" method in the Chessgame class. I
thought that i would reference the
begindate and enddate field as instance variables, but this did not work. I had
to write the code
like this:
-------------------------------------------------
require ''active_record''
class Chessgame < ActiveRecord::Base
def hours
(enddate - begindate) / 60 / 60 # Why no "@" sign in front of
begindate & enddate?
end
end
--------------------------------------------------
Why don''t the enddate & begindate fields show up in my class as
instance variables?
When I prefix the variables with an "@", then I get this message:
"NoMethodError in Chessgame#list"
Thanks,
--Nate