首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在heroku上运行带有gem的Ruby脚本失败:没有要加载的文件

在heroku上运行带有gem的Ruby脚本失败:没有要加载的文件
EN

Stack Overflow用户
提问于 2012-09-05 02:18:04
回答 1查看 851关注 0票数 1

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

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

代码语言:javascript
复制
require 'rubygems'
require 'mechanize'

puts "Success!"

我还有一个Gemfile:

代码语言:javascript
复制
source :rubygems
ruby '1.8.7'
gem 'mechanize'

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

代码语言:javascript
复制
~/Ruby/test % ruby test.rb
Success!

当我把它推给heroku时,它看起来很好

代码语言:javascript
复制
~/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

但是运行脚本失败:

代码语言:javascript
复制
~/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

提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-09-06 00:03:36

尝试运行:

heroku run bundle exec ruby test.rb

您指定了一个特定的ruby版本,因此需要使用该版本执行它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12269210

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档