w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Load gems inside scripts run from the shell outside our Rails application directory?

Be sure that your gem are all declared in your Gemfile:

gem 'mail'

If you don't want them to be loaded by default, and load them only when needed, you can use the require statement that you are already using, and in your Gemfile add :require => false:

gem 'mail', :require => false

When you call your script from outside your Rails environment, and want to load the gems, prefix your script by bundle exec:

bundle exec my_script.rb

If you need to run your script from another location than your rails's app root, you must run:

BUNDLE_GEMFILE=/path/to/your/app/Gemfile bundle exec your_script

Keep in mind though that this may cause path issues if your script or your gems are looking for file in the path of your rails app





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.