1

我想在 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

提前致谢!

4

1 回答 1

1

尝试运行:

heroku run bundle exec ruby test.rb

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

于 2012-09-05T16:03:35.890 回答