前提・実現したいこと
Railsチュートリアルをローカル環境で進めています。
bundle install --path vendor/bundle --without production
を実行後、
Rails Server起動し、localhost:3000にアクセスするとエラーが出てしまいます。
また、Rails Consoleでも同様のメッセージが出力されました。
エラーメッセージに従い、developmentでもpgのgemを入れればエラーは出力されなくなりましたが、
接続先をSqlite3としているので、なぜPostgreSQLでエラーとなってしまうのかがわかりません。
発生している問題・エラーメッセージ
zsh
1❯ rails s 2=> Booting Puma 3=> Rails 5.1.6 application starting in development 4=> Run `rails server -h` for more startup options 5Puma starting in single mode... 6* Version 3.9.1 (ruby 2.4.1-p111), codename: Private Caller 7* Min threads: 5, max threads: 5 8* Environment: development 9* Listening on tcp://0.0.0.0:3000 10Use Ctrl-C to stop 11Started GET "/" for 127.0.0.1 at 2019-02-03 21:57:06 +0900 12Processing by ApplicationController#hello as HTML 13Completed 500 Internal Server Error in 235ms 14 15 16 17Gem::LoadError (Specified 'postgresql' for database adapter, but the gem is not loaded. Add `gem 'pg'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).): 18 19app/controllers/application_controller.rb:5:in `hello'
該当のソースコード
database.yml
yml
1# SQLite version 3.x 2# gem install sqlite3 3# 4# Ensure the SQLite 3 gem is defined in your Gemfile 5# gem 'sqlite3' 6# 7default: &default 8 adapter: sqlite3 9 pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> 10 timeout: 5000 11 12development: 13 <<: *default 14 adapter: sqlite3 15 database: db/development.sqlite3 16 17# Warning: The database defined as "test" will be erased and 18# re-generated from your development database when you run "rake". 19# Do not set this db to the same as development or production. 20test: 21 <<: *default 22 database: db/test.sqlite3 23 24production: 25 <<: *default 26 database: db/production.sqlite3 27
Gemfile
1source 'https://rubygems.org' 2 3gem 'rails', '5.1.6' 4gem 'puma', '3.9.1' 5gem 'sass-rails', '5.0.6' 6gem 'uglifier', '3.2.0' 7gem 'coffee-rails', '4.2.2' 8gem 'jquery-rails', '4.3.1' 9gem 'turbolinks', '5.0.1' 10gem 'jbuilder', '2.6.4' 11 12group :development, :test do 13# gem 'pg', '0.20.0' ←これを書けばエラーで出力されないが、本来不要なはず 14 gem 'sqlite3', '1.3.13' 15 gem 'byebug', '9.0.6', platform: :mri 16end 17 18group :development do 19 gem 'web-console', '3.5.1' 20 gem 'listen', '3.1.5' 21 gem 'spring', '2.0.2' 22 gem 'spring-watcher-listen', '2.0.1' 23end 24 25group :production do 26 gem 'pg', '0.20.0' 27end 28
試したこと
rails aboutで確認した情報
zsh
1❯ rails about 2About your application's environment 3Rails version 5.1.6 4Ruby version 2.4.1-p111 (x86_64-darwin18) 5RubyGems version 2.6.11 6Rack version 2.0.6 7JavaScript Runtime Node.js (V8) 8Middleware Rack::Sendfile, ActionDispatch::Static, ActionDispatch::Executor, ActiveSupport::Cache::Strategy::LocalCache::Middleware, Rack::Runtime, Rack::MethodOverride, ActionDispatch::RequestId, ActionDispatch::RemoteIp, Sprockets::Rails::QuietAssets, Rails::Rack::Logger, ActionDispatch::ShowExceptions, WebConsole::Middleware, ActionDispatch::DebugExceptions, ActionDispatch::Reloader, ActionDispatch::Callbacks, ActiveRecord::Migration::CheckPending, ActionDispatch::Cookies, ActionDispatch::Session::CookieStore, ActionDispatch::Flash, Rack::Head, Rack::ConditionalGet, Rack::ETag 9Application root /Users/ユーザ名/environment/hello_app 10Environment development
Rubyはrbenvでinstallしたものを使用
zsh
1❯ which ruby 2/Users/ユーザ名/.rbenv/shims/ruby 3 4❯ rbenv local 52.4.1
回答1件
あなたの回答
tips
プレビュー