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

时间:2013-11-24 14:37:47

标签: ruby-on-rails sqlite3-ruby

我按照本教程开始使用rails: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec-the_first_application 这看起来很不错。

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

我按照教程进行操作,一切运行良好,安装正常(来自他的建议来源: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 server命令时,出现以下错误:

    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时,我得到了

  耙子流产了!   为数据库适配器指定'postgresql',但gem不是   加载。将gem 'pg'添加到您的Gemfile。

我认为这三个问题可能已连接,问题的根源在于启动rails服务器时出现错误消息。 我该怎么做才能修复它,它可能是ruby版本1.9.3而不是2.0.0吗?

谢谢!

编辑: On this link,我找到了关于whiny_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号固定:)

Edit2:在同一个链接中,我通过在配置文件中创建此配置并设置值来修复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

2 个答案:

答案 0 :(得分:1)

我建议我认为可以更好地为您提供解决方案:

从除rails之外的所有gem中删除版本号

它会做rails 4和ruby 2.0,对你来说ruby 2.0可能会有效。 如有必要,将ruby版本作为1.9.3

现在和将来,这对你来说可能会更好 最好避免使用其他宝石的所有特定版本号来避免......您遇到的版本问题。你希望花更多的时间在实际的应用程序,rails代码,ruby代码等上花费更多的时间。大多数宝石可以自己找出正确的版本和依赖项。

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

答案 1 :(得分:0)

解决:我的系统环境变量中有一个指向postgres DB的database_url。我很久以前在关注heroku教程时已经这样做了。我删除它,现在它工作正常。

相关问题