为什么我的rails服务器发出弃用警告,却没有连接到sqlite3



我正在按照本教程启动rails:http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec-第一个应用程序看起来很不错。

一开始,作者谈到了版本对宝石和软件的重要性,所以我尽我所能保持使用完全相同的版本。

我遵循了教程,一切都运行得很好,安装还可以(来自他的建议来源:http://railsinstaller.org/en)我下载了ruby 1.9。

安装后,我使用rails new first_app创建了我的应用程序,并将Gemfile更改为以下文件:

source 'https://rubygems.org'
ruby '1.9.3' #In the tutorial is 2.0.0, but changed to match my ruby version, 
             #as specified in the tutorial
#ruby-gemset=railstutorial_rails_4_0
gem 'rails', '4.0.1'
group :development do
  gem 'sqlite3', '1.3.8'
end
gem 'sass-rails', '4.0.1'
gem 'uglifier', '2.1.1'
gem 'coffee-rails', '4.0.1'
gem 'jquery-rails', '3.0.4'
gem 'turbolinks', '1.1.1'
gem 'jbuilder', '1.0.2'
group :doc do
  gem 'sdoc', '0.3.20', require: false
end

当我运行rails服务器命令时,我得到以下错误:

    DEPRECATION WARNING: config.whiny_nils option is deprecated and no longer works.
 (called from block in <top (required)> at D:/rails/first_app/config/environment
s/development.rb:10)
config.eager_load is set to nil. Please update your config/environments/*.rb fil
es accordingly:
  * development - set it to false
  * test - set it to false (unless you use a tool that preloads your test enviro
nment)
  * production - set it to true

但是打开localhost:3000运行良好。点击"关于你的应用程序的环境"链接,生成一个错误

ActiveRecord::ConnectionNotEstablished

Rails.root:D:/Rails/first_app

我检查了一下,我的database.yml正在使用sqlite3。

当我在应用程序的文件夹中运行rake-db:create时,我会得到

rake中止!为数据库适配器指定了"postgresql",但gem不是加载。将gem 'pg'添加到您的Gemfile中。

我认为这三个问题可能是相互关联的,问题的根源是启动rails服务器时的错误消息。我能做些什么来修复它,它会是ruby版本1.9.3而不是2.0.0吗?

谢谢!

编辑:在这个链接上,我找到了解决我在whichy_nils弃用上的问题的方法

Rails 4 removed the whiny_nils feature. Read more about it in the ActiveRecord chapter.
To solve the deprecation warning, simply remove any lines that set config.whiny_nils. Rails 3 added the configuration by default in config/environments/development.rb and config/environments/test.rb by default.

不知道为什么创建一个应用程序并用相同的版本启动它会导致这个问题,但好的。1号修复了:)

第2版:在同一个链接中,我通过在配置文件中创建这个配置并设置一个值来修复config.eager_load问题。

活动记录问题仍然存在。

编辑3:这是我的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

已解决:我的系统环境变量中有一个指向postgres DB的database_url。很久以前,我在学习heroku教程时就已经这样做了。我去掉了它,现在它工作得很好。

我建议一个我认为对您更有效的解决方案:

删除除rails 以外的所有宝石的版本号

它将执行rails 4和ruby 2.0,对您来说,ruby 2.0可能会起作用。如有必要,将ruby版本设为1.9.3

这可能对你现在和将来都更有效
最好避免其他宝石的所有特定版本号,以避免。。。。您遇到的版本问题。你想在这方面花更少的时间,而在实际的应用程序、rails代码、ruby代码等上花更多的时间。大多数gem都可以自己找出正确的版本和依赖项。

尝试以这种方式快速执行另一个应用程序(在再次发出rails新命令之前,请确保先"cd.."退出该应用程序)。你还会发现,与其他一些旧的框架相比,开发一个新的应用程序是一件非常频繁的事情。

最新更新