Frage

I deployed a small sinatra app on heroku. I get an internal server error message when I try to access the page. Here is what I get from heroku logs

2012-09-29T17:24:18+00:00 app[web.1]: TypeError - can't convert nil into an exact number:
2012-09-29T17:24:18+00:00 app[web.1]:   /app/birthday_countdown.rb:9:in `+'
2012-09-29T17:24:18+00:00 app[web.1]:   web.rb:5:in `block in <main>'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:1265:in `call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:1265:in `block in compile!'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `[]'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:851:in `route_eval'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `block (2 levels) in route!'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:870:in `process_route'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/birthday_countdown.rb:9:in `initialize'
2012-09-29T17:24:18+00:00 app[web.1]:   web.rb:5:in `new'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:833:in `each'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:936:in `dispatch!'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:769:in `block in call!'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:872:in `block in process_route'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:835:in `block (3 levels) in route!'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:870:in `catch'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in `block in invoke'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/rub
y/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in `catch'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:833:in `route!'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:769:in `call!'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:755:in `call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/json_csrf.rb:17:in `call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/base.rb:47:in `call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:834:in `block in route!'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/xss_header.rb:22:in `call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/logger.rb:15:in `call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:129:in `call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:921:in `invoke'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/head.rb:9:in `call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:99:in `call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:1389:in `block in call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:1471:in `synchronize'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:1389:in `call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/thin-1.4.1/lib/thin/connection.rb:78:in `pre_process'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/commonlogger.rb:20:in `call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.2.0/lib/rack/protection/path_traversal.rb:16:in `call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:1060:in `block in spawn_threadpool'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/thin-1.4.1/lib/thin/connection.rb:80:in `block in pre_process'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:in `call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.3.3/lib/sinatra/base.rb:136:in `call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/eventmachine-0.12.10/lib/eventmachine.rb:1060:in `call'
2012-09-29T17:24:18+00:00 app[web.1]:   /app/vendor/bundle/ruby/1.9.1/gems/thin-1.4.1/lib/thin/connection.rb:78:in `catch'
2012-09-29T17:24:18+00:00 app[web.1]: 180.215.44.250 - - [29/Sep/2012 17:24:18] "GET / HTTP/1.1" 500 30 0.0012
2012-09-29T17:24:18+00:00 heroku[router]: GET debo-ka-birthday.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=8ms status=500 bytes=30

I have made the following changes in my app,

@month = Time.at(Time.now.utc + Time.zone_offset('IST')).month
@day = Time.at(Time.now.utc + Time.zone_offset('IST')).day
@year = Time.at(Time.now.utc + Time.zone_offset('IST')).year

from

@month = Time.now.month
@day = Time.now.day
@year = Time.now.year

I did this because I wanted the time to be according to Indian Standard Time and not the time on heroku server. This however has broken the app, can someone tell me how to fix it?

War es hilfreich?

Lösung

“IST” isn’t one of the timezones included in the time standard library, so Time.zone_offset('IST') returns nil.

You can use the actual offset for IST instead:

Time.at(Time.now.utc + Time.zone_offset('+05:30')).month

It might be easier to use the localtime method:

Time.now.localtime('+05:30')

which gives the same result.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top