Ruby on Rails: How can I specify runner script environment Ruby on Rails: How can I specify runner script environment bash bash

Ruby on Rails: How can I specify runner script environment


The help on the command line for script/runner gives you your answer.

script/runner -e production Model.method


If that's your command, the order of your arguments is your biggest problem.

/usr/bin/ruby RAILS_ENV=production ../script/runner ../lib/tasks.rb

Is different than.

/usr/bin/ruby ../script/runner ../lib/tasks.rb RAILS_ENV=production

The second example is looking for the file, the first one is setting a runtime variable while ruby interpreting it as the file you want to run.


If you redo your script like this:

#!/bin/bashRAILS_ENV=production/usr/bin/ruby ../script/runner ../lib/tasks.rb

...that will make it stick for the lifetime of the script. To make it stick for the lifetime of the shell's session, change it to

#!/bin/bashexport RAILS_ENV=production/usr/bin/ruby ../script/runner ../lib/tasks.rb