LoginSignup
1
1

More than 5 years have passed since last update.

Calling ruby script in Rails

Posted at

Railsからrubyスクリプトを呼び出したら

./hoge.rb:3:in `require': cannot load such file -- fuga (LoadError)

というエラーとなった。
このスクリプトでは(Railsアプリにはない)fugaというgemを利用している。もちろんインストールはしてある状態。
どうやらRailsでは以下の環境変数が設定してある。

  • GEM_PATH
  • GEM_HOME
  • BUNDLE_BIN_PATH
  • BUNDLE_GEMFILE

このうち、BUNDLE_GEMFILEが存在すると、RailsのGemfileにあるモジュールしか使えなくなるようだ。
以下のようにunsetするシェルスクリプトを通したら実行できた。

in_rails_code
  result = system "~/bin/hoge.sh '#{args}'"

hoge.sh
#!/bin/sh
unset BUNDLE_GEMFILE
cd `dirname $0`
./hoge.rb $*
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1