1. ホーム
  2. ruby-on-rails

[解決済み] Ruby - ActiveRecord::ConnectionNotEstablished

2022-02-19 06:19:45

質問

私はRubyの初心者で、「Ruby On Rails 3 Tutorial - Learn Ruby by Example - by Michael Hartl"」という本についていっています。現在、第3章で静的ページについて説明しています。

この章では、プロンプトに次のようなコマンドを入力しました。 rails generate controller Pages home contact で、すべてうまくいきました。

その後、この本で指示された http://localhost:3000/pages/home . そこにブラウザを向けると、次のようなエラーが表示されます。

ActiveRecord::ConnectionNotEstablished(接続が確立されていません)

ActiveRecord::ConnectionNotEstablished(接続が確立されていません)
Rails.rootです。/home/ralph/railsprojects/sample_app

アプリケーショントレース|フレームワークトレース|フルトレース

routesとcontrollerのerbはエラーがないようです。これはデータベース関連のエラーなのでしょうか?何か思い当たることはありますか?

ありがとうございます。 DMAT

更新しました。

これは私の database.yml ファイルにあるコードです。

# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000

production:
  adapter: sqlite3
  database: db/production.sqlite3
  pool: 5
  timeout: 5000

以下は、Framework Traceからの情報です。

  activerecord (3.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:409:in `retrieve_connection'
  activerecord (3.1.1) lib/active_record/connection_adapters/abstract/connection_specification.rb:107:in `retrieve_connection'
  activerecord (3.1.1)lib/active_record/connection_adapters/abstract/connection_specification.rb:89:in `connection'
  activerecord (3.1.1) lib/active_record/query_cache.rb:65:in `call'
  activerecord (3.1.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:477:in `call'
  actionpack (3.1.1) lib/action_dispatch/middleware/callbacks.rb:29:in `call'
  activesupport (3.1.1) lib/active_support/callbacks.rb:392:in `_run_call_callbacks'
  activesupport (3.1.1) lib/active_support/callbacks.rb:81:in `send'
  activesupport (3.1.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (3.1.1) lib/action_dispatch/middleware/callbacks.rb:28:in `call'
  actionpack (3.1.1) lib/action_dispatch/middleware/reloader.rb:68:in `call'
  rack (1.3.5) lib/rack/sendfile.rb:101:in `call'
  actionpack (3.1.1) lib/action_dispatch/middleware/remote_ip.rb:48:in `call'
  actionpack (3.1.1) lib/action_dispatch/middleware/show_exceptions.rb:47:in `call'
  railties (3.1.1) lib/rails/rack/logger.rb:13:in `call'
  rack (1.3.5) lib/rack/methodoverride.rb:24:in `call'
  rack (1.3.5) lib/rack/runtime.rb:17:in `call'
  activesupport (3.1.1) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.3.5) lib/rack/lock.rb:15:in `call'
  actionpack (3.1.1) lib/action_dispatch/middleware/static.rb:53:in `call'
  railties (3.1.1) lib/rails/engine.rb:456:in `call'
  railties (3.1.1) lib/rails/rack/content_length.rb:16:in `call'
  railties (3.1.1) lib/rails/rack/log_tailer.rb:14:in `call'
  rack (1.3.5) lib/rack/handler/webrick.rb:59:in `service'
  /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
  /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
  /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
  /usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
  /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
  /usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
  /usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
  /usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
  /usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
  /usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
  rack (1.3.5) lib/rack/handler/webrick.rb:13:in `run'
  rack (1.3.5) lib/rack/server.rb:265:in `start'
  railties (3.1.1) lib/rails/commands/server.rb:70:in `start'
  railties (3.1.1) lib/rails/commands.rb:54
  railties (3.1.1) lib/rails/commands.rb:49:in `tap'
  railties (3.1.1) lib/rails/commands.rb:49
  script/rails:6:in `require'
  script/rails:6

解決方法は?

私は同じ問題に直面し、ゼロからサンプルアプリを起動し、このgemfileを使用しました。

source 'http://rubygems.org'

gem 'rails', '3.1.1'

gem 'sqlite3'

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


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

group :assets do
  gem 'sass-rails',   '~> 3.1.4'
  gem 'coffee-rails', '~> 3.1.1'
  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

これで問題は解決しました :)