ActiveRecord::ConnectionNotEstablished

Hello

I am rather new to Ruby and have been following along with the book
"Ruby On Rails 3 Tutorial - Learn Ruby by Example - by Michael Hartl".
I am currently in Chapter 3 which discusses static pages. In this
chapter, I entered the following command into the prompt: "rails
generate controller Pages home contact" and everything worked fine.
Then the book directs me to http://localhost:3000/pages/home. When I
point my browser there, I receive the following error.

ActiveRecord::ConnectionNotEstablished

ActiveRecord::ConnectionNotEstablished
Rails.root: /home/ralph/railsprojects/sample_app

Application Trace | Framework Trace | Full Trace

The routes and controller erb don't appear to have any errors. Is this
a database related error? Any ideas?

Thanks,
DMAT

what's the url for your git repo.... I'll take a look at it....

off the top of my head, it shouldn't be a db issue as there's no db at
that point of the tutorial... a quick google did make it sound like a
db issue... but i can't tell much unless i can look at the source

I have the exact same problem in chapter 3. I went over everything that
I could think can go wrong but wasn't successful.

This is my github directory : https://github.com/justfarnaz/sample_app
Really appreciate the help Max.

I am having similar issues regarding ConnectionNotEstablished. Anyone
able to resolve this problem? Appreciate any help.

Please send the exact error message.

If you doubt if the database.yml file is correct, you could do this test:

$ cd config

$ irb

001:0> require ‘yaml’

=> true

002:0> d = YAML.load(File.open(‘database.yml’))

=> {“development”=>{“adapter”=>“postgresql”, “encoding”=>“unicode”, …}}

003:0> quit

$ vim database.yml # place an incorrect TAB

$ irb

001:0> require ‘yaml’

=> true

002:0> d = YAML.load(File.open(‘database.yml’))

Psych::SyntaxError: (database.yml): couldn’t parse YAML at line 6 column 0

from /home/peterv/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych.rb:154:in `parse'

from /home/peterv/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych.rb:154:in `parse_stream'

from /home/peterv/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych.rb:125:in `parse'

from /home/peterv/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/psych.rb:112:in `load'

from (irb):2

from /home/peterv/.rvm/rubies/ruby-1.9.3-p0/bin/irb:16:in `<main>'

This way, at least you can make sure your database.yml file is correctly formatted.

You may also show us your database.yml file (but empty the password line …).

HTH,

Peter

Check your log/development.log I’m sure there is something there

I'm actually having the same problem running through the tutorial
exercises. I suspect it actually has something to do with RSpec as I
can't understand why it's trying to access the database as all the pages
are static. Additionally, the previous example in the tutorial which
contained database calls worked fine but I didn't have RSpec installed
at the time.

I tried to run rake db:create and get the following error message.

$ rake db:create --trace
rake aborted!
undefined method `prerequisites' for nil:NilClass

/Users/RKessler/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rspec-rails-2.0.1/lib/rspec/rails/tasks/rspec.rake:3:in
`<top (required)>'
/Users/RKessler/.rvm/gems/ruby-1.9.2-p290@rails3tutorial/gems/rspec-rails-2.0.1/lib/rspec-rails.rb:10:in
`load'

Any help would be greatly appreciated.

Thanks.

I had the same problem today as you described, and this is how I solved
it. I'm not sure if this is the "best" or most appropriate solution, but
it worked.

I changed my Gemfile and added the sqlite3 gem. After restarting the
server and reloading the page I received a new error:

ActionView::Template::Error (couldn't find file 'jquery'

So, I went back to the Gemfile again and added the jquery-ruby gem.
This time everything worked as expected. Maybe this has something do do
with the version of Rails and Ruby I/we have running? I'm running the
following:

ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]
Rails 3.1.1

Below is my Gemfile for the curious. Using this my sample app is working
fine now.

- Pete

change sqlite3-ruby with sqlite2 on Gemfile

Peter P. wrote in post #1032037:

I had the same problem today as you described, and this is how I solved
it. I'm not sure if this is the "best" or most appropriate solution, but
it worked.

I changed my Gemfile and added the sqlite3 gem. After restarting the
server and reloading the page I received a new error:

ActionView::Template::Error (couldn't find file 'jquery'

So, I went back to the Gemfile again and added the jquery-ruby gem.
This time everything worked as expected. Maybe this has something do do
with the version of Rails and Ruby I/we have running? I'm running the
following:

ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.2.0]
Rails 3.1.1

Below is my Gemfile for the curious. Using this my sample app is working
fine now.

- Pete

-------------------------
source 'http://rubygems.org'

gem 'rails', '3.1.1'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'
gem 'sqlite3-ruby', '1.3.1', :require => 'sqlite3'
gem 'jquery-rails'

group :development do
  gem 'rspec-rails', '2.0.1'
end

group :test do
  gem 'rspec', '2.0.1'
  gem 'webrat', '0.7.1'
end
-------------------------

Thanx!

I had to slightly mod my Gemfile from what have, but now it works!

My Gemfile:

source 'http://rubygems.org'

gem 'rails', '3.1.1'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'
gem 'sqlite3-ruby', '1.3.1', :require => 'sqlite3'
gem 'jquery-rails'

group :development do
  gem 'rspec-rails', '2.0.1'
end

group :test do
  gem 'rspec', '2.0.1'
  gem 'webrat', '0.7.1'
end

# in production environments by default.
group :assets do
  gem 'sass-rails', '~> 3.1.4'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'