【发布时间】:2013-11-24 14:37:46
【问题描述】:
我正在按照本教程开始使用 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 可以正常工作。点击“About your application's environment”链接,会产生错误
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?
谢谢!
编辑: 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
【问题讨论】:
-
如果你要使用 'postresql' 数据库(在 /config/database.yml 中),那么你必须在 Gemfile 中添加 postresql gem (gem 'pg')
-
不,我想使用 sqlite3 数据库。我不知道为什么 rake 引用 postgres :(
-
检查您的 /config/database.yml 文件是否有任何数据库的适配器设置为 postgresql
-
更新问题,但不,它没有。我确实有其他使用 postgres 的应用程序,但这个应该使用 sqlite。 rake 是否有可能从其他应用程序获取适配器信息?
-
Rails 默认会在 /db/development.sqlite3 中创建一个 sqlite 数据库。所以只需创建你的模型并运行
rake db:migrate。
标签: ruby-on-rails sqlite3-ruby