我在heroku上部署了一个小型的sinatra应用程序。我在尝试访问该页面时收到内部服务器错误消息。这是我从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
我在应用程序中进行了以下更改,
@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
从
@month = Time.now.month
@day = Time.now.day
@year = Time.now.year
我这样做是因为我希望时间根据印度标准时间,而不是 heroku 服务器上的时间。但是,这破坏了应用程序,有人可以告诉我如何解决它吗?
"
IST"不是time
标准库中包含的时区之一,因此Time.zone_offset('IST')
返回nil
。
您可以改用 IST 的实际偏移量:
Time.at(Time.now.utc + Time.zone_offset('+05:30')).month
使用 localtime
方法可能更容易:
Time.now.localtime('+05:30')
这给出了相同的结果。