Howto: setup the rails environment in a .rb script
Posted by Sandro Paganotti in
Ruby on Rails -
comments are closed
It can happen that you need to perform some operations on your rails application from a script, for example you may need to have a cron job that do something on your models. To archieve this goal you need to set up a rails environment in your script; it’s really easy, you’ve just to put these lines on the top of your .rb file.
RAILS_ROOT = RELATIVEPATHTOYOURAPPFOLDER
require RAILS_ROOT + "/config/environment"
Dependencies.load_file("application.rb")
I really don’t know why but you have to manually load application.rb, if you don’t rails translate the ‘ApplicationController’ constant into ‘application_controller’ and look for a file named ‘application_controller.rb’ that doesn’t exist.
Sandro.


Comments
fallenrogue
Posted on February 15
edbond
Posted on February 15