Thursday, September 10, 2009

How to Run (Load) a .rb (Ruby) Script in Rails

If you don't need Rails, you can just run a Ruby script at command-line:
ruby path/to/file/some_script.rb

But if your script requires to be run in your Rails project environment:

cd (root of rails project)
load 'path/to/file/some_script.rb'

Load will execute the script every time you do the load, unlike require which will only run it once (and for require you remove the .rb extension at the end of the filename).

See also:

No comments: