Forum: Ruby on Rails rake aborted! ActiveRecord::ConnectionNotEstablished

Posted by Joshua Muheim (josh)
on 2006-05-16 23:48
Hi all

I'm just learning to use rake and ran into the following problem:

chraftbuech:/Users/Josh/Webwork/CommentingSystem josh$ rake 
create_test_news
(in /Users/Josh/Webwork/CommentingSystem)
Create test news
rake aborted!
ActiveRecord::ConnectionNotEstablished

The task's code is:

desc 'Creates some test news items with comments'
task 'create_test_news' do
  puts 'Create test news'
  n = NewsItem.new
  n.subject = 'This is the first news item'
  n.body = 'After days of work this is the first news item ever 
published using the NewsEngine. Have fun with it and add some comments! 
:-)'
  raise 'Could not save first news item!' if !n.save
end

Can you tell me what I have to do to establish the connection? I guess 
somehow Rails doesn't connect to MySQL?

Thanks for help. :-)
Joshua
Posted by Al Evans (al-evans)
on 2006-05-17 01:22
Joshua Muheim wrote:

> Can you tell me what I have to do to establish the connection? I guess 
> somehow Rails doesn't connect to MySQL?

This is probably way too obvious, but do you have your database 
connection set up in config/database.yml?

If not, that could cause it.

I got this error the other day in an especially dopey way. I was working 
on a non-database application, and had added

config.frameworks -= [ :action_web_service, :action_mailer, 
:active_record ]

to environment.rb to save memory.

Then I decided to add an OpenProfile authentication controller to it, so 
I added a database to keep track of users.

It took me two hours to figure out why I couldn't connect to the 
database:-)

--Al Evans
Posted by Joshua Muheim (josh)
on 2006-05-17 10:25
Al Evans wrote:
> Joshua Muheim wrote:
> 
>> Can you tell me what I have to do to establish the connection? I guess 
>> somehow Rails doesn't connect to MySQL?
> 
> This is probably way too obvious, but do you have your database 
> connection set up in config/database.yml?
It's correctly set up, because over the console I can create the items 
without any problems... :-/ there's something wrong with rake, I 
guess...
Posted by Joshua Muheim (josh)
on 2006-05-17 10:29
I just remarked that every task in the UserEngine engine is dependent on 
:environment:

desc 'Create the default roles'
task :create_roles => :environment do
  ...
end

Do I need to add this dependence too? But where does this :environment 
task come from? It's definitely not in my rake file... ;-)
Posted by Joshua Muheim (josh)
on 2006-05-17 10:32
LOL funny that I can't edit my posts here... ;-)

It was really that I have to add the dependence :environment to the 
task:

desc 'Creates some test news items with comments'
task :create_test_news => :environment do
  puts 'Create test news'
  n = NewsItem.new
  n.subject = 'This is the first news item'
  n.body = 'After days of work this is the first news item ever 
published using the NewsEngine. Have fun with it and add some comments! 
:-)'
  raise 'Could not save first news item!' if !n.save
end

But still the question: where is this task defined?
Posted by James Adam (Guest)
on 2006-05-17 10:45
(Received via mailing list)
The :environment task comes from Rails' own Rakefiles - so either in
the gems, or in your copy of Rails in vendor
(RAILS_ROOT/vendor/rails/railties/lib/tasks/misc.rake, I believe)

- james
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.