2

我对 Ruby 和一般编程比较陌生。我在大约 6 个月前创建了这个应用程序,它搜索顶级 twitter 和 google 趋势以输出 youtube 中所有最受欢迎视频的 JSON 文件。我已经将它部署到 Heroku 并且在 twitter api 1 更新到 api 1.1 之前没有任何问题。6 个月前,为了了解在本地和 heroku 中运行的 twitter 趋势,我的代码看起来像这样。

    if trendLocation == nil
        result = JSON.parse(open("https://api.twitter.com/1/trends/1.json").read)
    end

    if trendLocation.to_i == 23424977
        result = JSON.parse(open("https://api.twitter.com/1/trends/23424977.json").read)
    end

    topTen = result.first["trends"]
    panelArray = Array.new      

( https://api.twitter.com/1/trends/23424977.json ) 曾经是一个开源软件,它直接为我提供了 twitter 的热门趋势(无需身份验证)。自从 Twitter API 1.1 更新以来,链接不再存在,我必须对我的应用程序进行身份验证才能了解趋势。现在,每次我在 Url 中调用 Twitter 趋势时,我的应用程序都会崩溃。但是当我呼吁谷歌趋势时,它在本地和 Heroku 中运行得非常好。

所以我下载了 'twitter' 和 'oauth' gem 来使用 Twitter::Client 验证我的应用程序。我把我的代码改成了这个。

def getPanelsForTwitter(panelMaxCount)

    client = Twitter::Client.new(
        :consumer_key => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
        :consumer_secret => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
        :oauth_token => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
        :oauth_token_secret => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
    )

    usa = client.trends(23424977)
    world = client.trends(1)

    trendLocation = params[:woeid]

    if trendLocation == nil
        result = world
    end

    if trendLocation.to_i == 23424977
        result = usa
    end

    panelArray = Array.new      

end

一切都在本地运行并完成它需要做的一切(例如获取 twitter 和 google 趋势、在 youtube 上搜索并显示视频结果)。但是当我将它推送到 Heroku 时,应用程序崩溃了,但是当我将它推送或部署到 Heroku 时,它无法运行。

我运行了heroku日志,这就是我得到的


2013-10-13T19:38:31.623556+00:00 app[web.1]: => Call with -d to detach
2013-10-13T19:38:31.623556+00:00 app[web.1]: => Ctrl-C to shutdown server
2013-10-13T19:38:31.631953+00:00 app[web.1]: Exiting
2013-10-13T19:38:31.635716+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:225:in `require_dependency'
2013-10-13T19:38:31.635811+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/engine.rb:439:in `block (2 levels) in eager_load!'
2013-10-13T19:38:31.635811+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/engine.rb:438:in `block in eager_load!'
2013-10-13T19:38:31.635716+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:312:in `depend_on'
2013-10-13T19:38:31.635670+00:00 app[web.1]: /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/dependencies.rb:317:in `rescue in depend_on': No such file to load -- oAuth (LoadError)
2013-10-13T19:38:31.635811+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/engine.rb:438:in `each'
2013-10-13T19:38:31.635811+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `instance_exec'
2013-10-13T19:38:31.635811+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/engine.rb:436:in `eager_load!'
2013-10-13T19:38:31.635811+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/engine.rb:436:in `each'
2013-10-13T19:38:31.635811+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `run'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `run_initializers'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application.rb:136:in `initialize!'
2013-10-13T19:38:31.635811+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:55:in `block in run_initializers'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.4/lib/rack/builder.rb:51:in `initialize'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/config/environment.rb:5:in `<top (required)>'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/config.ru:3:in `require'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/config.ru:3:in `block in <main>'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.4/lib/rack/builder.rb:51:in `instance_eval'
2013-10-13T19:38:31.635811+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application/finisher.rb:53:in `block in <module:Finisher>'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.4/lib/rack/builder.rb:40:in `eval'
2013-10-13T19:38:31.635811+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `each'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:50:in `tap'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.4/lib/rack/server.rb:200:in `app'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands/server.rb:46:in `app'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.4/lib/rack/server.rb:304:in `wrapped_app'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/railtie/configurable.rb:30:in `method_missing'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.4/lib/rack/builder.rb:40:in `parse_file'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:55:in `block in <top (required)>'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/config.ru:in `new'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/config.ru:in `<main>'
2013-10-13T19:38:31.636437+00:00 app[web.1]:    from script/rails:6:in `require'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.4/lib/rack/server.rb:254:in `start'
2013-10-13T19:38:31.636437+00:00 app[web.1]:    from script/rails:6:in `<main>'
2013-10-13T19:38:31.636008+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands/server.rb:70:in `start'
2013-10-13T19:38:31.636437+00:00 app[web.1]:    from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:50:in `<top (required)>'
2013-10-13T19:38:33.267427+00:00 heroku[web.1]: State changed from starting to crashed
2013-10-13T19:38:33.252069+00:00 heroku[web.1]: Process exited with status 1
2013-10-13T19:38:35.105276+00:00 heroku[run.1165]: Awaiting client
2013-10-13T19:38:35.237705+00:00 heroku[run.1165]: Starting process with command `bundle`
2013-10-13T19:38:37.592953+00:00 heroku[run.1165]: State changed from starting to complete
2013-10-13T19:38:37.583575+00:00 heroku[run.1165]: Process exited with status 0
2013-10-13T19:38:51.535832+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/trends?p=10&v=10&source=gt&woeid=23424977 host=radiant-plains-2608.herokuapp.com fwd="50.129.228.74" dyno= connect= service= status=503 bytes=
129.228.74" dyno= connect= service= status=503 bytes=
2013-10-13T19:37:58.326215+00:00 heroku[web.1]: State changed from starting to crashed

==================================================== =======================

我得到的第一个错误是(3.2.9/lib/active_support/dependencies.rb:317:in `rescue independ_on': No such file to load -- oAuth (LoadError))。

所以我假设我的宝石有问题,我认为本地的宝石和 heroku 中的宝石不匹配。

这是我的 gemfile.lock

GEM
  remote: https://rubygems.org/
  specs:
    actionmailer (3.2.9)
      actionpack (= 3.2.9)
      mail (~> 2.4.4)
    actionpack (3.2.9)
      activemodel (= 3.2.9)
      activesupport (= 3.2.9)
      builder (~> 3.0.0)
      erubis (~> 2.7.0)
      journey (~> 1.0.4)
      rack (~> 1.4.0)
      rack-cache (~> 1.2)
      rack-test (~> 0.6.1)
      sprockets (~> 2.2.1)
    activemodel (3.2.9)
      activesupport (= 3.2.9)
      builder (~> 3.0.0)
    activerecord (3.2.9)
      activemodel (= 3.2.9)
      activesupport (= 3.2.9)
      arel (~> 3.0.2)
      tzinfo (~> 0.3.29)
    activeresource (3.2.9)
      activemodel (= 3.2.9)
      activesupport (= 3.2.9)
    activesupport (3.2.9)
      i18n (~> 0.6)
      multi_json (~> 1.0)
    arel (3.0.2)
    builder (3.0.4)
    coffee-rails (3.2.2)
      coffee-script (>= 2.2.0)
      railties (~> 3.2.0)
    coffee-script (2.2.0)
      coffee-script-source
      execjs
    coffee-script-source (1.4.0)
    erubis (2.7.0)
    execjs (1.4.0)
      multi_json (~> 1.0)
    faraday (0.8.5)
      multipart-post (~> 1.1)
    hike (1.2.1)
    httpauth (0.2.0)
    i18n (0.6.1)
    journey (1.0.4)
    jquery-rails (2.2.0)
      railties (>= 3.0, < 5.0)
      thor (>= 0.14, < 2.0)
    json (1.7.6)
    jwt (0.1.5)
      multi_json (>= 1.0)
    mail (2.4.4)
      i18n (>= 0.4.0)
      mime-types (~> 1.16)
      treetop (~> 1.4.8)
    mime-types (1.19)
    multi_json (1.5.0)
    multi_xml (0.5.3)
    multipart-post (1.1.5)
    nokogiri (1.5.6)
    oauth (0.4.7)
    oauth2 (0.9.1)
      faraday (~> 0.8)
      httpauth (~> 0.1)
      jwt (~> 0.1.4)
      multi_json (~> 1.0)
      multi_xml (~> 0.5)
      rack (~> 1.2)
    pg (0.14.1)
    polyglot (0.3.3)
    rack (1.4.4)
    rack-cache (1.2)
      rack (>= 0.4)
    rack-ssl (1.3.2)
      rack
    rack-test (0.6.2)
      rack (>= 1.0)
    rails (3.2.9)
      actionmailer (= 3.2.9)
      actionpack (= 3.2.9)
      activerecord (= 3.2.9)
      activeresource (= 3.2.9)
      activesupport (= 3.2.9)
      bundler (~> 1.0)
      railties (= 3.2.9)
    railties (3.2.9)
      actionpack (= 3.2.9)
      activesupport (= 3.2.9)
      rack-ssl (~> 1.3.2)
      rake (>= 0.8.7)
      rdoc (~> 3.4)
      thor (>= 0.14.6, < 2.0)
    rake (10.0.3)
    rdoc (3.12)
      json (~> 1.4)
    sass (3.2.5)
    sass-rails (3.2.6)
      railties (~> 3.2.0)
      sass (>= 3.1.10)
      tilt (~> 1.3)
    simple_oauth (0.2.0)
    sprockets (2.2.2)
      hike (~> 1.2)
      multi_json (~> 1.0)
      rack (~> 1.0)
      tilt (~> 1.1, != 1.3.0)
    sqlite3 (1.3.7)
    thor (0.17.0)
    tilt (1.3.3)
    treetop (1.4.12)
      polyglot
      polyglot (>= 0.3.1)
    twitter (4.8.1)
      faraday (~> 0.8, < 0.10)
      multi_json (~> 1.0)
      simple_oauth (~> 0.2)
    tzinfo (0.3.35)
    uglifier (1.3.0)
      execjs (>= 0.3.0)
      multi_json (~> 1.0, >= 1.0.2)
    youtube_it (2.1.13)
      builder
      faraday (~> 0.8)
      nokogiri (~> 1.5.2)
      oauth (~> 0.4.4)
      oauth2 (~> 0.6)
      simple_oauth (>= 0.1.5)

PLATFORMS
  ruby

DEPENDENCIES
  coffee-rails (~> 3.2.1)
  jquery-rails
  oauth
  pg
  rails (= 3.2.9)
  sass-rails (~> 3.2.3)
  sqlite3
  twitter (>= 4.8.1)
  uglifier (>= 1.0.3)
  youtube_it

当我在本地运行 gem list 和运行 heroku run gem list 时,一切都匹配。我尝试卸载 'twitter' 和 'oauth' gems,然后重新安装并运行 bundle install,但仍然遇到同样的问题。

在目前的状态下,我的应用程序只能在本地运行,根本不能在 Heroku(live)中运行,即使我试图只获取谷歌趋势。整个应用程序崩溃。

当我在 Heroku 中回滚到六个月前时,该应用程序仅在我从 twitter 调用某些内容时才会崩溃。其他一切都在 Heroku 中运行。

这让我相信,当它试图读取 gemfile 时,这是一个 Heroku 部署问题。正确的?我错过了什么吗?还有其他我可以使用的宝石吗?或者这不是宝石问题吗?

github:https ://github.com/meeks16/webservice

谢谢

4

2 回答 2

1

谢谢大家的意见。终于发现这有什么问题了。我很粗心,但这是一个简单的语法错误。我在heroku日志中的错误是..

`rescue in depend_on': No such file to load -- oAuth (LoadError)

我有一个单独的 temps_controller,它有一个我完全忘记的 require 'oAuth'。宝石“oAuth”不存在,它被认为是“oauth”。这就是应用程序在部署到 heroku 时崩溃的原因。我有点惊讶和困惑为什么它在本地工作。我猜 localhost 对这些错误更宽容?

当我部署到实时站点时,我真的应该小心。通过删除我用于测试的所有临时文件,确保清理我的代码。也许避免在控制器中使用 require 。只需安装所需的 gem。

这是一个如此简单而愚蠢的错误,花了我一点时间,但绝对学到了很多东西。

于 2013-10-17T18:37:57.543 回答
0

我认为您在评论中得到了一些很好的答案,但您可能还想查看Twitter Gem以确保您不会将您的公共 API 密钥扔到可能受到损害的地方

于 2013-10-12T12:03:27.660 回答