Joshua Muheim
2006-May-16 21:48 UTC
[Rails] rake aborted! ActiveRecord::ConnectionNotEstablished
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 via http://www.ruby-forum.com/.
Al Evans
2006-May-16 23:22 UTC
[Rails] Re: rake aborted! ActiveRecord::ConnectionNotEstablished
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 via http://www.ruby-forum.com/.
Joshua Muheim
2006-May-17 08:26 UTC
[Rails] Re: rake aborted! ActiveRecord::ConnectionNotEstablished
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 via http://www.ruby-forum.com/.
Joshua Muheim
2006-May-17 08:29 UTC
[Rails] Re: rake aborted! ActiveRecord::ConnectionNotEstablished
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 via http://www.ruby-forum.com/.
Joshua Muheim
2006-May-17 08:32 UTC
[Rails] Re: rake aborted! ActiveRecord::ConnectionNotEstablished
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 via http://www.ruby-forum.com/.
James Adam
2006-May-17 08:44 UTC
[Rails] Re: rake aborted! ActiveRecord::ConnectionNotEstablished
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 On 5/17/06, Joshua Muheim <forum@josh.ch> wrote:> 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 via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-- * J * ~