I've got a simple class, defined by the following table in a
create_table :buzzusers do |t|
t.integer :level, :default => 0
I usually create it with the following
Buzzuser.create(:name => "Bob")
which works fine. It appears to save and load fine. I've written the
following method within the Buzzuser class model:
@level += 1
This blows up with a nil error when called. More precisely, I get:
NoMethodError: You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.+
However, if I'm outside the class, I can access the level variable
just fine. If I do
bu = Buzzuser.find(1)
I can then do bu.level and it returns the correct value for level.
What's wrong? I'm assuming I'm missing something basic, but it's