Books I Like

Saturday, February 9, 2008

Rails Error : ActiveRecord::AdapterNotSpecified


I was playing a bit with Ruby on Rails (RoR). Till now the experience (I am a newbie) has been great with this framework !




When tried generating a model (User) ,received this error:-
>ruby script/generate model User

C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/connection_a
dapters/abstract/connection_specification.rb:217:in `establish_connection': deve
lopment database is not configured (ActiveRecord::AdapterNotSpecified)
from C:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record
/connection_adapters/abstract/connection_specification.rb:208:in `establish_conn
ection'
from C:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:234:i
n `initialize_database'
from C:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:94:in
`process'
from C:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:49:in
`send'
from C:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/initializer.rb:49:in
`run'
from C:/Projects/Personal/Rails/rails_space/config/environment.rb:13
from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `ge
m_original_require'
from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `re
quire'
from C:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/generate.rb
:1
from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `ge
m_original_require'
from C:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `re
quire'
from script/generate:3

Searched a bit over the net, and was sure that there is some problem with my database.yml file.

Couldn't find anything concrete, as I checked to make sure that there is no "tab" space used in the file.

The culprit was the indentation.

In the figure, can you see the difference? In the first case, the arguments after the"development" are properly indented (one space). In the second case, since there is no such indentation, the interpreter attempts to consider "adapter" (and the rests) at the same level as the "development". Try to avoid that.

Hopefully it will save other's efforts.

Get at Amazon