How can I set the Rails environment for my somewhat stand alone Ruby script?
Posted
by Nick
on Stack Overflow
See other posts from Stack Overflow
or by Nick
Published on 2009-02-09T19:56:37Z
Indexed on
2010/04/07
23:03 UTC
Read the original article
Hit count: 209
ruby-on-rails
|ruby
I have a Ruby script in my Rails app that I use to load some data from Twitter.
In the future I will make it an automatic background process, but for now I run it manually like:
ruby /lib/twitter/twitterLoad.rb
In order to use the Rails model classes and such, I have the following as the top line of the script:
require "#{File.dirname(__FILE__)}/../../config/environment.rb"
By default, the development environment is used. But, I'd like to be able to choose the production environment at some point.
Update #1: The RAILS_ENV constant is getting set in the environment.rb file. So, I was able to put ENV['RAILS_ENV'] = 'production' at the very top (before the environment.rb) line and solve my problem somewhat. So, my new question is, can do pass in env vars through the command line?
© Stack Overflow or respective owner