【问题标题】:Running Ruby script with gems on heroku fails: no such file to load在 heroku 上运行带有 gems 的 Ruby 脚本失败:没有要加载的文件
【发布时间】:2012-09-04 18:18:03
【问题描述】:

我想在 heroku 服务器上运行一个 ruby​​ 脚本。问题是当我在 Heroku 上运行脚本时,它似乎看不到任何宝石! 这是我刚刚创建的示例测试情况。

我在 test.rb 文件中有一个简单的 Ruby 脚本:

require 'rubygems'
require 'mechanize'

puts "Success!"

我也有一个 Gemfile:

source :rubygems
ruby '1.8.7'
gem 'mechanize'

一切都在我的本地机器上运行

~/Ruby/test % ruby test.rb
Success!

当我将它推送到 heroku 时,它看起来不错

~/Ruby/test % git push heroku master
Enter passphrase for key '/home/sadie/.ssh/id_rsa': 
Counting objects: 9, done.
Compressing objects: 100% (7/7), done.
Writing objects: 100% (9/9), 1.02 KiB, done.
Total 9 (delta 1), reused 0 (delta 0)
-----> Heroku receiving push
-----> Ruby app detected
-----> Using Ruby version: ruby-1.8.7
-----> Installing dependencies using Bundler version 1.2.0
       Running: bundle install --without development:test --path vendor/bundle --binstubs bin/ --deployment
       Fetching gem metadata from http://rubygems.org/.......
       Installing unf_ext (0.0.5) with native extensions
       Installing unf (0.0.5)
       Installing domain_name (0.5.3)
       Installing mime-types (1.19)
       Installing net-http-digest_auth (1.2.1)
       Installing net-http-persistent (2.7)
       Installing nokogiri (1.5.5) with native extensions
       Installing ntlm-http (0.1.1)
       Installing webrobots (0.0.13)
       Installing mechanize (2.5.1)
       Using bundler (1.2.0)
       Your bundle is complete! It was installed into ./vendor/bundle
       Cleaning up the bundler cache.
-----> Discovering process types
       Procfile declares types -> (none)
       Default types for Ruby  -> console, rake
-----> Compiled slug size is 7.3MB
-----> Launching... done, v3
       http://nameless-river-3415.herokuapp.com deployed to Heroku

To git@heroku.com:nameless-river-3415.git
 * [new branch]      master -> master

但运行脚本失败:

~/Ruby/test % heroku run 'ruby test.rb'
Running `ruby test.rb` attached to terminal... up, run.1
/app/vendor/ruby-1.8.7/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `gem_original_require': no such file to load -- mechanize (LoadError)
    from /app/vendor/ruby-1.8.7/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:36:in `require'
    from test.rb:2

提前致谢!

【问题讨论】:

    标签: ruby deployment heroku rubygems


    【解决方案1】:

    尝试运行:

    heroku run bundle exec ruby test.rb

    你指定了一个特定的 ruby​​ 版本,所以你需要用它来执行它。

    【讨论】:

      猜你喜欢
      • 2012-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-09
      • 2015-09-06
      • 2013-02-20
      • 1970-01-01
      • 2013-07-09
      相关资源
      最近更新 更多