我对编程很陌生,只是试图将我的第一个项目放到网上,却遇到了内部服务器错误。我什至不知道从哪里开始,我在 Sinatra 上运行 Ruby 并将其托管在 Heroku
这是我对服务器的 lass 请求的 ruby 日志,希望我正确地发布了这个问题。任何帮助将非常感激
2013-04-10T03:30:14.733305+00:00 app[web.1]: TypeError - nil can't be coerced into Float:
2013-04-10T03:30:14.733305+00:00 app[web.1]: /app/app.rb:35:in `-'
2013-04-10T03:30:14.733305+00:00 app[web.1]: /app/app.rb:35:in `block in <top (required)>'
2013-04-10T03:30:14.733305+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1415:in `call'
2013-04-10T03:30:14.733305+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1415:in `block in compile!'
2013-04-10T03:30:14.733305+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:944:in `[]'
2013-04-10T03:30:14.733305+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:944:in `block (3 levels) in route!'
2013-04-10T03:30:14.733305+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:960:in `route_eval'
2013-04-10T03:30:14.733305+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:944:in `block (2 levels) in route!'
2013-04-10T03:30:14.733305+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:981:in `block in process_route'
2013-04-10T03:30:14.733614+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:979:in `catch'
2013-04-10T03:30:14.733614+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:979:in `process_route'
2013-04-10T03:30:14.733614+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:943:in `block in route!'
2013-04-10T03:30:14.733614+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:942:in `each'
2013-04-10T03:30:14.733614+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:942:in `route!'
2013-04-10T03:30:14.733614+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1053:in `block in dispatch!'
2013-04-10T03:30:14.733614+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1035:in `block in invoke'
2013-04-10T03:30:14.733614+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1035:in `catch'
2013-04-10T03:30:14.733614+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1035:in `invoke'
2013-04-10T03:30:14.733614+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1050:in `dispatch!'
2013-04-10T03:30:14.733865+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:878:in `block in call!'
2013-04-10T03:30:14.733865+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1035:in `block in invoke'
2013-04-10T03:30:14.733865+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1035:in `catch'
2013-04-10T03:30:14.733865+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1035:in `invoke'
2013-04-10T03:30:14.733865+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:878:in `call!'
2013-04-10T03:30:14.733865+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:864:in `call'
2013-04-10T03:30:14.733865+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.5.0/lib/rack/protection/xss_header.rb:18:in `call'
2013-04-10T03:30:14.733865+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.5.0/lib/rack/protection/path_traversal.rb:16:in `call'
2013-04-10T03:30:14.741803+00:00 heroku[router]: at=info method=GET path=/ host=clearli.herokuapp.com fwd="69.159.113.216" dyno=web.1 connect=1ms service=1474ms status=500 bytes=30
2013-04-10T03:30:14.733865+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.5.0/lib/rack/protection/json_csrf.rb:18:in `call'
2013-04-10T03:30:14.733865+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.5.0/lib/rack/protection/base.rb:49:in `call'
2013-04-10T03:30:14.734121+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.5.0/lib/rack/protection/base.rb:49:in `call'
2013-04-10T03:30:14.734121+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-protection-1.5.0/lib/rack/protection/frame_options.rb:31:in `call'
2013-04-10T03:30:14.734121+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/logger.rb:15:in `call'
2013-04-10T03:30:14.734121+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/commonlogger.rb:33:in `call'
2013-04-10T03:30:14.734121+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:209:in `call'
2013-04-10T03:30:14.734121+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:202:in `call'
2013-04-10T03:30:14.734121+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/head.rb:11:in `call'
2013-04-10T03:30:14.734121+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
2013-04-10T03:30:14.734121+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:172:in `call'
2013-04-10T03:30:14.734121+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1947:in `call'
2013-04-10T03:30:14.734355+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1610:in `block in call'
2013-04-10T03:30:14.734355+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1693:in `synchronize'
2013-04-10T03:30:14.734355+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/sinatra-1.4.2/lib/sinatra/base.rb:1610:in `call'
2013-04-10T03:30:14.734355+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
2013-04-10T03:30:14.734355+00:00 app[web.1]: /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
2013-04-10T03:30:14.734355+00:00 app[web.1]: /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
2013-04-10T03:30:14.734355+00:00 app[web.1]: /usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in `block in start_thread'
2013-04-10T03:30:14.734355+00:00 app[web.1]: 69.159.113.216 - - [10/Apr/2013 03:30:14] "GET / HTTP/1.1" 500 30 1.4439
2013-04-10T03:30:16.891604+00:00 heroku[router]: at=info method=GET path=/ host=clearli.herokuapp.com fwd="69.159.113.216" dyno=web.1 connect=1ms service=1268ms status=500 bytes=30
应用程序.rb
require 'rubygems'
require 'sinatra'
require 'haml'
require 'hashie'
require 'forecast_io'
require 'shotgun'
require 'geocoder'
Geocoder.configure(:timeout => 60)
Forecast::IO.configure do |configuration|
configuration.api_key = 'fe6fa0b5700a6134723fabdb8a08b296'
end
get '/' do
result = request.location
@lat = result.latitude
@long = result.longitude
city = request.location.city
@city = city
forecast = Forecast::IO.forecast(@lat, @long)
@current_temp = forecast.currently.temperature
@current_wind = (forecast.currently.windSpeed)
@current_icon = forecast.currently.icon
@current_clouds = forecast.currently.cloudCover
yesterday = Forecast::IO.forecast(@lat, @long, time: (Time.new.to_i - 86400))
@yesterday_temp = yesterday.currently.temperature
@yesterday_wind = (yesterday.currently.windSpeed)
@yesterday_clouds = yesterday.currently.cloudCover
@temp_difference = (@current_temp - @yesterday_temp)
@temp_difference_abs = @temp_difference.abs
@wind_difference = (((@current_wind - @yesterday_wind)/@yesterday_wind)*100)
@cloud_difference = (((@current_clouds - @yesterday_clouds)/@yesterday_clouds)*100)
@temp_description = "warmer"
if @temp_difference < 0
@temp_description = "colder"
end
@wind_description = "you dont need to worry about the wind"
if (@wind_difference >= 0 && @wind_difference <= 50)
@wind_description = "a bit windier"
elsif (@wind_difference > 50 && @wind_difference <= 100)
@wind_description = "noticeably windier"
elsif (@wind_difference > 100)
@wind_description = "much more windy"
elsif (@wind_difference <= 0 && @wind_difference >= -50)
@wind_description = "a bit less windy"
elsif (@wind_difference < -50 && @wind_difference >= -100)
@wind_description = "noticeably less windy"
elsif (@wind_difference < -100)
@wind_description = "way less windy"
end
@cloud_description = "no brighter or cloudier than"
if (@cloud_difference >= 0 && @cloud_difference <= 25)
@cloud_description = "a bit cloudier than"
elsif (@cloud_difference > 25 && @cloud_difference <= 75)
@cloud_description = "much more cloudy than"
elsif (@cloud_difference > 75)
@cloud_description = "disgustingly cloudy compared to"
elsif (@cloud_difference < 0 && @cloud_difference >= -25)
@cloud_description = "a bit clearer than"
elsif (@cloud_difference < -25 && @cloud_difference >= -75)
@cloud_description = "way clearer than"
elsif (@cloud_difference < -75)
@cloud_description = "incredibly clear compared to"
end
@unit = "degrees"
if @temp_difference == 1 || @temp_difference == -1
@unit = "degree"
end
haml :index
end