Ruby - ActiveRecord::ConnectionNotEstablished [英] Ruby - ActiveRecord::ConnectionNotEstablished

查看:50
本文介绍了Ruby - ActiveRecord::ConnectionNotEstablished的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Ruby 比较陌生,一直在关注Ruby On Rails 3 教程 - 通过示例学习 Ruby - Michael Hartl"一书.我目前在讨论静态页面的第 3 章.

在本章中,我在提示中输入了以下命令:rails generate controller Pages home contact 一切正常.

然后这本书将我引导到 http://localhost:3000/pages/home.当我将浏览器指向那里时,我收到以下错误.

<前>ActiveRecord::ConnectionNotEstablishedActiveRecord::ConnectionNotEstablishedRails.root:/home/ralph/railsprojects/sample_app应用程序跟踪 |框架跟踪 |完整跟踪

路由和控制器 erb 似乎没有任何错误.这是与数据库相关的错误吗?有什么想法吗?

谢谢,DMAT

更新:

这是我的database.yml文件中的代码.

# SQLite 3.x 版# gem 安装 sqlite3## 确保在您的 Gemfile 中定义了 SQLite 3 gem# gem 'sqlite3'发展:适配器:sqlite3数据库:db/development.sqlite3池:5超时:5000# 警告:定义为test"的数据库将被删除并# 运行rake"时从开发数据库重新生成.# 不要将此数据库设置为与开发或生产相同.测试:适配器:sqlite3数据库:db/test.sqlite3池:5超时:5000生产:适配器:sqlite3数据库:db/production.sqlite3池:5超时:5000

以下是来自框架跟踪的信息:

 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'机架 (1.3.5) lib/rack/handler/webrick.rb:13:in `run'机架 (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:54railties (3.1.1) lib/rails/commands.rb:49:in `tap'railties (3.1.1) lib/rails/commands.rb:49脚本/导轨:6:在`要求'脚本/导轨:6

解决方案

我遇到了同样的问题,我从头开始使用示例应用程序并使用了这个 gemfile:

源'http://rubygems.org'宝石导轨",3.1.1"宝石'sqlite3'组:开发做宝石rspec-rails",2.6.1"结尾组:测试做宝石rspec-rails",2.6.1"宝石webrat",0.7.1"结尾组:资产做gem 'sass-rails', '~>3.1.4'gem '咖啡轨','~>3.1.1'gem 'uglifier', '>= 1.0.3'结尾宝石'jquery-rails'

这为我解决了问题:)

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

Update:

This is the code in my database.yml file.

# 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

Here is the information from the 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

解决方案

I had the same problem, I started the sample-app from scratch and used this 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'

This solved the problem for me :)

这篇关于Ruby - ActiveRecord::ConnectionNotEstablished的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆