簡體   English   中英

如何在任何時候為Rails gem指定rvm gemset?

[英]How to specify rvm gemsets for Rails gem whenever?

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

我正在使用gem“無論何時”來定期發送電子郵件通知。 這是我的schedule.rb:

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

除非默認使用gemset 1.9.3@rails-3.2,否則Cron作業將無法正常工作。 我如何改善我的schedule.rb以便為我的scheduller使用另一個gemset(不僅是默認的@global)。

我已經閱讀了官方文檔: 每當rvm問題以及關於“何時使用rvm gemsets”的stackoverflow問題,但沒有找到答案。

我試圖將以下代碼(根據RVM-Notes中的建議)放在我的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? 非常感謝!

UPDATE

1)我試圖為我的Gemfile提供rvm注意:

ruby=ruby-1.9.3-p448 # with # sign

ruby-gemset=rails-3.2 # with # sign

沒有任何結果。 沒有什么變化。

2)我試圖修改我的〜/ .rvmrc。 實驗了完整的捆綁路徑,rails給了我以下錯誤列表:

    /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實驗:

#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 ,bundler僅添加環境變量以使用來自Gemfile gem,而不修改加載的ruby環境。

此處描述了類似情況http://rvm.io/integration/init-d

嘗試

job_type :runner, "cd :path && RAILS_ENV=:environment bundle exec rails runner :task :output"

假設您在Gemfile提到了

#ruby=ruby-1.9.3-p448
#ruby-gemset=rails-3.2

有關此符號,請參見RVM文檔

嘗試在項目根目錄中創建.rvmrc文件,並包含以下行

rvm use 1.9.3@rails-3.2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM