我想在heroku服务器上运行ruby脚本。问题是,当我在Heroku上运行脚本时,似乎看不到宝石! 这是我刚刚创建的示例测试情况。
我在Ruby中的test.rb文件中有一个简单的脚本:
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
提前致谢!
答案 0 :(得分:1)
尝试跑步:
heroku run bundle exec ruby test.rb
您指定了特定的ruby版本,因此您需要使用该版本执行它。