Using ActiveRecord in a Rake Task

I have the following skeleton for a rake task:

==========
namespace :db do

desc “Populate database for first time based on export from AS/400
system”
task :populate_from_export do
ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[‘development’])
User.find(:all)
puts “hello world”
end

end

I want to be able to call User.find(:all) from my rake task but I am
getting the following error:

development database is not configured

If I get rid of the first line of the task I get the following error:

ActiveRecord::ConnectionNotEstablished

So how do I make a proper conneection and make my models accessible to
me for a rake task?

Thanks for your help :-).

Your Friend,

John


John K.
[email protected]

http://www.kopanas.com
http://www.cusec.net
http://www.soen.info

On 11/21/06, John K. [email protected] wrote:

I have the following skeleton for a rake task:

==========
namespace :db do

desc “Populate database for first time based on export from AS/400 system”
task :populate_from_export do

You need to make sure your config files are loaded. Try:

task :populate_from_export => [ :environment ] do

instead of the line above my comment.

Isak

Perfect… thanks :-).

On 11/21/06, Isak H. [email protected] wrote:

ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations['development'])

development database is not configured
Your Friend,


John K.
[email protected]

http://www.kopanas.com
http://www.cusec.net
http://www.soen.info

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs