如何在任何时候为Rails gem指定rvm gemset? [英] How to specify rvm gemsets for Rails gem whenever?

查看:68
本文介绍了如何在任何时候为Rails gem指定rvm gemset?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MyApp使用的是rvm gemset 1.9.3@rails-3.2。这不是默认值。

MyApp is using rvm gemset 1.9.3@rails-3.2. It is not default.

我使用的是随时随地 gem定期发送电子邮件通知。这是我的schedule.rb:

I am using gem 'whenever' to periodically send email notifications. This is my schedule.rb:

every 1.minutes do
 runner "MyModel.send_emails" # if ... 
end 

Cron工作不起作用,除非gemset 1.9.3@rails-3.2默认。我该如何改善schedule.rb以便为我的调度程序使用其他gemset(不仅是默认@global)。

Cron job is not working unless gemset 1.9.3@rails-3.2 is default. How can i improve my schedule.rb in order to use another gemsets (not only default @global) for my scheduller.

我已经阅读了官方文档:何时 rvm问题和有关何时需要rvm宝石集的stackoverflow问题,但没有找到答案。

I have read official documentation: whenever and rvm issues and stackoverflow questions about "rvm gemsets for whenever", but have not found an answer.

我尝试提出以下内容代码(根据RVM-Notes中的建议)在我的shedule.rb中:

I have tried to put the following code (according to advice in RVM-Notes) in my shedule.rb:

job_type :runner, "{ cd #{@current_path} > /home/####/.rvm/gems/ruby-1.9.3-p448@
rails-3.2/bin/rails; } && RAILS_ENV=:environment bundle exec rails runner ':task' :output"

但没有结果:

ERROR: 
/home/###/.rvm/gems/ruby-1.9.3-p448@global/gems/bundler-1.3.5/lib/bundler/spec_set.rb:92
:in `block in materialize': Could not find i18n-0.6.5 in any of the sources
(Bundler::GemNotFound)

如何为Rails gem指定rvm gemset '每当'?非常感谢!

How to specify rvm gemsets for Rails gem 'whenever'? Many thanks!

更新

1)我试图提供rvm注意对于我的Gemfile,像这样:

1) I have tried to provide rvm notaions for my Gemfile like this:

ruby=ruby-1.9.3-p448 # with # sign

ruby-gemset=rails-3.2 # with # sign

没有结果。没什么改变。

It gives no result. Nothing changes.

2)我试图修改〜/ .rvmrc。实验了完整的捆绑路径,rails给了我以下错误列表:

2) I have tried to modify my ~/.rvmrc. Experiments with full path to bundle, rails gives me the following list of errors:

    /usr/bin/env: ruby: No such file or directory
    /usr/bin/env: ruby: No such file or directory
    /bin/bash: bundle: command not found
    /bin/bash: bundle: command not found
    /usr/bin/env: ruby_executable_hooks/usr/bin/env: ruby_executable_hooks: No such file or directory
   : No such file or directory

按工作类型实验在这里

#job_type :runner, "{ cd #{path}; } && RAILS_ENV=:environment bundle exec rails runner ':task' :output"
 job_type :runner, "{ cd #{path}; } && RAILS_ENV=:environment /home/###/.rvm/gems/ruby-1.9.3-p448@global/bin/bundle exec rails runner ':task' :output"
#job_type :runner, "cd #{path} && RAILS_ENV=development /home/###/.rvm/gems/ruby-1.9.3-p448@global/bin/bundle exec /home/###/.rvm/gems/ruby-1.9.3-p448@rails-3.2/bin/rails runner ':task' :output"


推荐答案

使用包装器:

job_type :runner, "cd #{path} && RAILS_ENV=development /home/###/.rvm/wrappers/ruby-1.9.3-p448@rails-3.2/bundle exec rails runner ':task' :output"

这将加载正确的rvm环境并在其上下文中运行 bundle ,捆绑程序仅添加要使用的环境变量 Gemfile 中的宝石,而无需修改加载的红宝石环境。

this will load proper rvm environment and run bundle in its context, bundler only adds environment variables for using gems from Gemfile without modifying the loaded ruby environment.

此处描述了类似的情况 http://rvm.io/integration/init-d

a similar situation is described here http://rvm.io/integration/init-d

这篇关于如何在任何时候为Rails gem指定rvm gemset?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆