jeudi 9 avril 2015

ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter

I need help in debuging this error:



ActiveRecord::AdapterNotSpecified: database configuration does not specify adapter on /.rbenv/versions/1.9.3-p448/lib/ruby/gems/1.9.1/gems/activerecord-3.2.21/lib/active_record/connection_adapters/abstract/connection_specification.rb:49:in `resolve_hash_connection'



This error is generated after I run the following rake task:



bundle exec rake myapi:populate_terminals RAILS_ENV=development




require 'active_record'
require 'yaml'


namespace :myapi do
task :populate_terminals do
files= %w(terminal lodge lodge/term)
files.each{ |f| require "#{ rails_root }/app/models/#{ f }" }

Terminal.populate
end
end


the error occurs in the 'establish_connection' line of lodge.rb



require 'net/http'
module Lodge

#Parent class for Lodge models
class Lodge::Base < ActiveRecord::Base


establish_connection "lodge_#{Rails.env}"

end
end


This is how my database.yml file looks like:



development:
adapter: oracle_enhanced
username: ****
password: ****
database: ****

lodge_development:
adapter: oracle_enhanced
database: ***
username: ***
password: ***


I did a binding.pry to make sure what lodge_#{Rails.env} returns and it seems to return the correct environment:



lodge_development



now I tried to debug bit more and print outed some variables from activerecord-3.2.21/lib/active_record/connection_adapters/abstract/connection_specification.rb:49



def resolve_string_connection(spec) # :nodoc:
hash = configurations.fetch(spec) do |k|
connection_url_to_hash(k)
end
p configurations
p spec
raise(AdapterNotSpecified, "#{spec} database is not configured") unless hash

resolve_hash_connection hash
end

def resolve_hash_connection(spec) # :nodoc:
spec = spec.symbolize_keys

puts "#{spec.inspect} ------------>"
raise(AdapterNotSpecified, "database configuration does not specify adapter") unless spec.key?(:adapter)
.
.
end


I got the following output:




'{}'


"ltv_development" {:database=>"ltv_development"} ------------>



I also did a bundle to make sure the appropriaate gems are installed.


I am kind of baffled and not sure how to proceed forward.


Aucun commentaire:

Enregistrer un commentaire