问题: 我有两个应用程序 A 和 B 都在同一台服务器上运行。我的文件系统中有一个脚本
cd /data/B/
bundle exec rake -T
当我通过应用程序 A 的 Rails 控制台运行脚本时,它会出错,因为控制台加载 A 的 gem,并且 rake 任务失败
eg: system("sh ~/test.sh")
rake aborted!
LoadError: cannot load such file -- log4r
/home/kumolus/api/config/application.rb:9:in `require'
/home/kumolus/api/config/application.rb:9:in `<top (required)>'
/home/kumolus/api/Rakefile:1:in `require'
/home/kumolus/api/Rakefile:1:in `<top (required)>'
(See full trace by running task with --trace)
当我通过 unix 命令行运行脚本时(无论我的密码如何)它都有效
cd ~
sh test.sh #works
cd /data/A #my application A's dir
sh ~/test.sh #also works
我需要它通过 Rails 工作。有什么帮助吗?谢谢!
最佳答案
谢谢大家的帮助, 由于 bundler 的默认行为,我找到了一个解决方案。
我将 with_clean_env 方法与一个 block 一起使用,它被执行。
感谢团队 干杯
关于ruby-on-rails - 我们如何通过另一个应用程序(都在同一服务器上运行)运行一个应用程序的 rake 任务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33231299/