Hello,
...at least I'm pretty sure its called ActiveRecord. I have an app
running on InstantRails 1.6 that will periodically call a ruby script in
the /script folder. In the script, I use the same models to connect to
my database as the ones in the rest of the app, but it doesn't seem to
work. I'm using "Model.connection.select_all('sql statement')" where
Model is the name of the model. Do I have to call a special gem or
something?
Hello,
...at least I'm pretty sure its called ActiveRecord. I have an app
running on InstantRails 1.6 that will periodically call a ruby script in
the /script folder. In the script, I use the same models to connect to
my database as the ones in the rest of the app, but it doesn't seem to
work. I'm using "Model.connection.select_all('sql statement')" where
Model is the name of the model. Do I have to call a special gem or
something?
you need to include your "environment.rb"
sticking this line;
require File.expand_path(File.dirname(__FILE__) +
"/../config/environment")
at the top of your file should load up rails, giving you access to all
of your models.
I think another way to do this is with script/runner. I think you can
use script runner in place of sh or tcsh (e.g. #! script/runner as the
first line of the script file) and that is supposed to load the
environment. See script/runner -help. I haven't tried it myself yet,
but was just learning about it.