There are slightly different answers depending on what you want to do.
I'm assuming that you do want to use your app's models (ie it's not
just activerecord you want, you need to setup the environment
The easiest way is to use script/runner, which will setup the
environment for you. Failing that, requiring config/boot and config/
environment will load up the rails environment for you. (those aren't
on the load path, so you'll need something like require
File.dirname(__FILE__) + '/../config/boot' depending on where your
script is in relation to the rest of the app)
Fred
I'd suggest you may also want to make this script get run by a rake task
/lib/tasks/whatever.rake
desc "whatever you want"
task :something => :environment do
Call::The.code_you_want
end
then just get cron to call the rake command.
--
Posted via http://www.ruby-forum.com/.
require 'rubygems'
require 'active_record'
It's all in the wiki:
http://wiki.rubyonrails.org/rails/pages/HowToUseActiveRecordOutsideRails
it won't get you the connection setup in your database.yml,
or any of the subclasses of ActiveRecord::Base that you've set up in
your project.
Just depends what you're trying to do.