2

私はこのチュートリアルに従ってレールを開始しています: http://ruby.railstutorial.org/ruby-on-rails-tutorial-book#sec-the_first_application とてもいいようです。

冒頭で著者がgemとソフトウェアのバージョンの重要性について語っているので、私はまったく同じバージョンを使い続けるように最善を尽くしました。

チュートリアルに従ったところ、すべて問題なく実行されました。インストールは問題ありませんでした (彼の推奨ソースから: 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に追加します。

おそらくこの3つの問題が関連していて、問題の原因はRailsサーバー起動時のエラーメッセージだと思います。2.0.0 ではなく、Ruby バージョン 1.9.3 である可能性がありますか?

ありがとう!

編集: このリンクで、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.

アプリを作成して同じバージョンで起動すると、この問題が発生する理由はわかりませんが、問題ありません。No.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
4

2 に答える 2