How to use Rails framework in stand alone ruby file ??? (+)

Good day.

I want to run rb-script via Cron, for inseringt data in
database.
Is it possible using ActiveRecord, for accessing to DBMS. What
should I reguire in rb-file ?

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

Falko wrote:

Good day.

I want to run rb-script via Cron, for inseringt data in
database.
Is it possible using ActiveRecord, for accessing to DBMS. What
should I reguire in rb-file ?

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.

Falko wrote:

Good day.

I want to run rb-script via Cron, for inseringt data in
database.
Is it possible using ActiveRecord, for accessing to DBMS. What
should I reguire in rb-file ?

Hi,

require 'rubygems'
require 'active_record'

It's all in the wiki:
http://wiki.rubyonrails.org/rails/pages/HowToUseActiveRecordOutsideRails

Fernando Perez wrote:

require 'rubygems'
require 'active_record'

It's all in the wiki:
http://wiki.rubyonrails.org/rails/pages/HowToUseActiveRecordOutsideRails

although,
that will only get you ActiveRecord...

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.

Creating a rake task is the far best solution. You can access all your
Models ideal for cron jobs. I use this on one of my projects which
updates/add many models every night.