I’m developing a small application in Ruby-On-Rails. In a controller I have this piece of code:
@user = User.find(current_user.id)
@user.number = current_user.number + 1
@user.save!
Although it locally runs without problems, it crashes on Heroku at line two, with the following error:
NoMethodError (undefined method `+’ for nil:NilClass)
Any tips on how to solve the problem?
If you are storing the number as attribute in your database you should set the default state to 0.
create new migration and regenerate the number column.