I have a bit of ruby code:
def createCal(cal)
mod = @on + @off #line creating error.
@daycount = 0
cal
end
This generates the following error: NoMethodError at /calendar undefined method `+’ for nil:NilClass file: main.rb location: createCal line: 83
I am using this in Sinatra, and so I can print out @on and @off onto a webpage and I can confirm that they are in fact being loaded with values. I also do a ‘@ooo = @on + @off’ in my haml template and that produces 7, which is to be expected because on is 4 and off 3.
Any ideas?
UPDATE:
Here’s how I’m handling @on and @off
post '/calendar' do
@on = params["on"]
@off = params["off"]
@date = params["date"]
a = Doer.new
@var = a.makeDate(@date)
@on = @on.to_i
@off = @off.to_i
@ooo = @on + @off
@cal = a.makeCal(@var)
haml :feeling
end
You’re accessing two different instance variables:
@oninpostis an instance variable for your Sinatra instance.@onincreateCalis an instance variable from your Doer instance.To use
@onand@offlike you want, you’ll need to change them into arguments passed to thecreateCalmethod. Something like this: