nil error?

Gary H. wrote:

Hi everyone,

I'm sure I'm doing something stupid with this, so if somebody could talk
some sense into me that would be great :slight_smile:

I'm trying to just increment a variable and I think I'm missing some
basic concept (this is RoR 2.0.2 btw)

So have a "players" table with several variables, including one called
"odds". I'm using the basic scaffold generator for the CRUD stuff, but
in my model I have:

  attr_reader :odds

  def initialize(odds)
    @odds = odds

This results in:
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.+

I can view the correct odds number by using 'puts odds.to_s' but it
won't let me set it at any point. Am I missing something?

Thanks in advance!

This is just a guess, but I would try replacing attr_reader with
attr_accessor. It may be that since you're not telling ruby to make a
method for setting odds, that it is unable to set it via the @odds

I'm no expert, but I play one on tv.