2015-11-20 65 views
1

我完全陌生于Ruby on Rails,我正在尝试一下。 我提前说,我没有找到答案,以适应我的问题,也没有在这里StackOverflow也没有在互联网上(我尝试了很多不同的东西从SO和其他网站中挑选)。未建立连接 - Ruby on Rails

我下面Rails的僵尸2CodeSchool,我需要来设置环境,以使事情发生。

为了做到这一点,我正在从迈克尔哈特的 Ruby on Rails教程继续设置阶段。

我跟着亦步亦趋,但是,当我很想看到: “你好,世界” 在浏览器中,我得到:

ActiveRecord::ConnectionNotEstablished 

No connection pool for ActiveRecord::Base 

完整跟踪:

activerecord (4.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:566:in `retrieve_connection' 
activerecord (4.2.2) lib/active_record/connection_handling.rb:113:in `retrieve_connection' 
activerecord (4.2.2) lib/active_record/connection_handling.rb:87:in `connection' 
activerecord (4.2.2) lib/active_record/query_cache.rb:51:in `restore_query_cache_settings' 
activerecord (4.2.2) lib/active_record/query_cache.rb:43:in `rescue in call' 
activerecord (4.2.2) lib/active_record/query_cache.rb:31:in `call' 
activerecord (4.2.2) lib/active_record/connection_adapters/abstract/connection_pool.rb:649:in `call' 
actionpack (4.2.2) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' 
activesupport (4.2.2) lib/active_support/callbacks.rb:88:in `call' 
activesupport (4.2.2) lib/active_support/callbacks.rb:88:in `_run_callbacks' 
activesupport (4.2.2) lib/active_support/callbacks.rb:776:in `_run_call_callbacks' 
activesupport (4.2.2) lib/active_support/callbacks.rb:81:in `run_callbacks' 
actionpack (4.2.2) lib/action_dispatch/middleware/callbacks.rb:27:in `call' 
actionpack (4.2.2) lib/action_dispatch/middleware/reloader.rb:73:in `call' 
actionpack (4.2.2) lib/action_dispatch/middleware/remote_ip.rb:78:in `call' 
web-console (2.0.0.beta3) lib/action_dispatch/debug_exceptions.rb:18:in `middleware_call' 
web-console (2.0.0.beta3) lib/action_dispatch/debug_exceptions.rb:13:in `call' 
actionpack (4.2.2) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 
railties (4.2.2) lib/rails/rack/logger.rb:38:in `call_app' 
railties (4.2.2) lib/rails/rack/logger.rb:20:in `block in call' 
activesupport (4.2.2) lib/active_support/tagged_logging.rb:68:in `block in tagged' 
activesupport (4.2.2) lib/active_support/tagged_logging.rb:26:in `tagged' 
activesupport (4.2.2) lib/active_support/tagged_logging.rb:68:in `tagged' 
railties (4.2.2) lib/rails/rack/logger.rb:20:in `call' 
actionpack (4.2.2) lib/action_dispatch/middleware/request_id.rb:21:in `call' 
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call' 
rack (1.6.4) lib/rack/runtime.rb:18:in `call' 
activesupport (4.2.2) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' 
rack (1.6.4) lib/rack/lock.rb:17:in `call' 
actionpack (4.2.2) lib/action_dispatch/middleware/static.rb:113:in `call' 
rack (1.6.4) lib/rack/sendfile.rb:113:in `call' 
railties (4.2.2) lib/rails/engine.rb:518:in `call' 
railties (4.2.2) lib/rails/application.rb:164:in `call' 
rack (1.6.4) lib/rack/lock.rb:17:in `call' 
rack (1.6.4) lib/rack/content_length.rb:15:in `call' 
rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service' 

在得到这个之前,我安装了Rails,我进入了我的hello_app文件夹并使用了:Bundle Install,然后我使用了:Rails Server。我还删除了指南中所述的index.html。

我的Gemfile:

source 'https://rubygems.org' 

gem 'rails',    '4.2.2' 
gem 'sass-rails',   '5.0.2' 
gem 'uglifier',    '2.5.3' 
gem 'coffee-rails',   '4.1.0' 
gem 'jquery-rails',   '>= 3.0.0' 
gem 'turbolinks',   '2.3.0' 
gem 'jbuilder',    '2.2.3' 
gem 'sdoc',     '0.4.0', group: :doc 

group :development, :test do 
    gem 'sqlite3' 
    gem 'pry-byebug', platform: [:ruby_20] 
    gem 'web-console', '2.0.0.beta3' 
    gem 'spring',  '1.1.3' 
end 

我的应用程序控制器:

class ApplicationController < ActionController::Base 
     protect_from_forgery with: :exception 

     def hello 
     render text: "hello, world!" 
     end 
end 

我的路线:

HelloApp::Application.routes.draw do 
     root 'application#hello 
end 

我的数据库:

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

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

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

对不起,如果我的问题是微不足道的,我也对不起我的可怕的英语。

预先感谢您!

回答

0

我自己解决了。这是一个由Gemfile破坏引起的问题。 ,让我让它工作权的配置是:

的Gemfile:

source 'https://rubygems.org' 


# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' 
gem 'rails', '4.2.2' 
# Use sqlite3 as the database for Active Record 
gem 'sqlite3' 
# Use SCSS for stylesheets 
gem 'sass-rails', '~> 5.0' 
# Use Uglifier as compressor for JavaScript assets 
gem 'uglifier', '>= 1.3.0' 
# Use CoffeeScript for .coffee assets and views 
gem 'coffee-rails', '~> 4.1.0' 
# See https://github.com/rails/execjs#readme for more supported  runtimes 
# gem 'therubyracer', platforms: :ruby 

# Use jquery as the JavaScript library 
gem 'jquery-rails' 
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks 
gem 'turbolinks' 
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder 
gem 'jbuilder', '~> 2.0' 
# bundle exec rake doc:rails generates the API under doc/api. 
gem 'sdoc', '~> 0.4.0', group: :doc 

# Use ActiveModel has_secure_password 
# gem 'bcrypt', '~> 3.1.7' 

# Use Unicorn as the app server 
# gem 'unicorn' 

# Use Capistrano for deployment 
# gem 'capistrano-rails', group: :development 

group :development, :test do 
# Call 'debugger' anywhere in the code to stop execution and get a debugger console 
    gem 'debugger' 

# Access an IRB console on exception pages or by using <%= console %> in views 
    gem 'web-console', '~> 2.0' 

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring 
    gem 'spring' 
end 
2

顺便说一句,你有没有在启动服务器之前运行bundle exec rake db:setup?看起来好像你的数据库还不存在(你可以检查db/development.sqlite3文件是否存在)。

+0

谢谢您的回答,但运行'捆绑高管耙分贝:setup'不工作,我会得到相同的像以前一样。 ** db/development.sqlite3 **确实存在,但它是空的。任何想法? – AndreaM16

+0

它不起作用或什么都不做?它是'db:setup'(里面没有空格)。也可以尝试'rake db:create'。 –

+0

此文件不应该为空 - 您应该可以使用某些sqlite编辑器打开它,例如,http://sqlitebrowser.org/ –