Tuesday, October 23, 2012

Running Script within Radar Environment

You can run a ruby script within rails environment by adding the following two lines to head of script.

require File.join(File.dirname(__FILE__), "..", "config", "boot")
require File.join(File.dirname(__FILE__), "..", "config", "environment")

These two lines setup the rails environment, e.g. ActiveRecord. Your script now has entire Rails/radar set of classes available to it.

The script should be run from application home directory as such:


ruby script/your_script.rb

See script/load_students.rb for an example.

No comments:

Post a Comment