To initialize a Rails environment instead of hosting
require "#{File.dirname(__FILE__)}/../config/environment.rb"
run the batch file using script/runner and specify the environment with the -e option
eg.
script/runner -e production lib/batch.rb
I think the Rails method described above is for writing and executing a script that requires a Rails infrastructure initialized to work. An alternative, like neutrino , is a command prefix with RAILS_ENV = value, for example.
$ RAILS_ENV=production lib/batch.rb
This is a standard shell function for setting an environment variable before executing a command.
mikej source share