質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

1435閲覧

Railsチュートリアルがherokuで動かない

tra

総合スコア10

Heroku

HerokuはHeroku社が開発と運営を行っているPaaSの名称です。RubyやNode.js、Python、そしてJVMベース(Java、Scala、Clojureなど)の複数のプログラミング言語をサポートしている。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

0グッド

0クリップ

投稿2018/12/05 08:33

前提・実現したいこと

Railsチュートリアル1章(https://railstutorial.jp/chapters/beginning?version=5.1#code-rails_command)をローカル環境でやっています。
heroku環境で動かしたいです。

rails serverではhello_appが動作するのですが、heroku上ではApplicationErrorになっています。しかし原因が分かりません。どこの何をどうすれば解決できるのか教えていただけませんでしょうか。

発生している問題・エラーメッセージ

Application error

該当のソースコード

terminal

1vim Gemfile 2bundle install --without production 3git commit -a -m "Update Gemfile for Heroku" 4git push heroku master 5heroku open

Gemfile

1source 'https://rubygems.org' 2 3# git_source(:github) do |repo_name| 4# repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") 5# "https://github.com/#{repo_name}.git" 6# end 7 8 9# Rails tutorial setting 10gem 'rails', '5.1.6' 11gem 'puma', '3.9.1' 12gem 'sass-rails', '5.0.6' 13gem 'uglifier', '3.2.0' 14gem 'coffee-rails', '4.2.2' 15gem 'jquery-rails', '4.3.1' 16gem 'turbolinks', '5.0.1' 17gem 'jbuilder', '2.6.4' 18 19group :development, :test do 20 gem 'sqlite3', '1.3.13' 21 gem 'byebug', '9.0.6', platform: :mri 22end 23 24group :development do 25 gem 'web-console', '3.5.1' 26 gem 'listen', '3.1.5' 27 gem 'spring', '2.0.2' 28 gem 'spring-watcher-listen', '2.0.1' 29end 30 31group :production do 32 gem 'pg', '0.20.0' 33end 34 35# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 36gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]

試したこと

$ heroku run rails console

Running rails console on ⬢ intense-ravine-83722... up, run.6449 (Free) /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/connection_specification.rb:188:in `rescue in spec': Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord). (Gem::LoadError) from /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/connection_specification.rb:185:in `spec' from /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/connection_adapters/abstract/connection_pool.rb:880:in `establish_connection' from /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/connection_handling.rb:58:in `establish_connection' from /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/railtie.rb:124:in `block (2 levels) in <class:Railtie>' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:69:in `instance_eval' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:69:in `block in execute_hook' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:60:in `with_execution_control' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:65:in `execute_hook' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:50:in `block in run_load_hooks' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:49:in `each' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/lazy_load_hooks.rb:49:in `run_load_hooks' from /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/base.rb:326:in `<module:ActiveRecord>' from /app/vendor/bundle/ruby/2.4.0/gems/activerecord-5.1.6/lib/active_record/base.rb:25:in `<top (required)>' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `block in require' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:258:in `load_dependency' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require' from /app/app/models/application_record.rb:1:in `<top (required)>' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `block in require' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:258:in `load_dependency' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:292:in `require' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:379:in `block in require_or_load' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:36:in `block in load_interlock' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies/interlock.rb:12:in `block in loading' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/concurrency/share_lock.rb:149:in `exclusive' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies/interlock.rb:11:in `loading' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:36:in `load_interlock' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:357:in `require_or_load' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:335:in `depend_on' from /app/vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/dependencies.rb:251:in `require_dependency' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:476:in `block (2 levels) in eager_load!' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:475:in `each' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:475:in `block in eager_load!' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:473:in `each' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:473:in `eager_load!' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:354:in `eager_load!' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/application/finisher.rb:67:in `each' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/application/finisher.rb:67:in `block in <module:Finisher>' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `instance_exec' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:30:in `run' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:59:in `block in run_initializers' from /app/vendor/ruby-2.4.5/lib/ruby/2.4.0/tsort.rb:228:in `block in tsort_each' from /app/vendor/ruby-2.4.5/lib/ruby/2.4.0/tsort.rb:350:in `block (2 levels) in each_strongly_connected_component' from /app/vendor/ruby-2.4.5/lib/ruby/2.4.0/tsort.rb:431:in `each_strongly_connected_component_from' from /app/vendor/ruby-2.4.5/lib/ruby/2.4.0/tsort.rb:349:in `block in each_strongly_connected_component' from /app/vendor/ruby-2.4.5/lib/ruby/2.4.0/tsort.rb:347:in `each' from /app/vendor/ruby-2.4.5/lib/ruby/2.4.0/tsort.rb:347:in `call' from /app/vendor/ruby-2.4.5/lib/ruby/2.4.0/tsort.rb:347:in `each_strongly_connected_component' from /app/vendor/ruby-2.4.5/lib/ruby/2.4.0/tsort.rb:226:in `tsort_each' from /app/vendor/ruby-2.4.5/lib/ruby/2.4.0/tsort.rb:205:in `tsort_each' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/initializable.rb:58:in `run_initializers' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/application.rb:353:in `initialize!' from /app/config/environment.rb:5:in `<top (required)>' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/application.rb:329:in `require' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/application.rb:329:in `require_environment!' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/command/actions.rb:16:in `require_application_and_environment!' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands/console/console_command.rb:96:in `perform' from /app/vendor/bundle/ruby/2.4.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run' from /app/vendor/bundle/ruby/2.4.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command' from /app/vendor/bundle/ruby/2.4.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/command/base.rb:63:in `perform' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/command.rb:44:in `invoke' from /app/vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/commands.rb:16:in `<top (required)>' from /app/bin/rails:9:in `require' from /app/bin/rails:9:in `<main>'

補足情報(FW/ツールのバージョンなど)

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

$brew install postgresql $sudo gem install sqlite3 -v '1.3.13' -- --with-sqlite3-lib=/usr/lib $bundle config build.sqlite3 --with-sqlite3-lib=/usr/lib $bundle install --path vendor/bundle

上記をやってもダメだったので、

  • heroku(ブラウザ)のプロジェクトを全削除
  • git reset --hard でheroku処理前に戻す

をやったのち、

Gemfile

1source 'https://rubygems.org' 2 3# git_source(:github) do |repo_name| 4# repo_name = "#{repo_name}/#{repo_name}" unless repo_name.include?("/") 5# "https://github.com/#{repo_name}.git" 6# end 7 8 9# Rails tutorial setting 10gem 'rails', '5.1.6' 11gem 'puma', '3.9.1' 12gem 'sass-rails', '5.0.6' 13gem 'uglifier', '3.2.0' 14gem 'coffee-rails', '4.2.2' 15gem 'jquery-rails', '4.3.1' 16gem 'turbolinks', '5.0.1' 17gem 'jbuilder', '2.6.4' 18 19group :development, :test do 20 gem 'sqlite3', '1.3.13' # sqlite3 gemをdevelop, test環境だけで使い、production環境では使わない(heropとの競合を防ぐ) 21 gem 'byebug', '9.0.6', platform: :mri 22end 23 24group :development do 25 gem 'web-console', '3.5.1' 26 gem 'listen', '3.1.5' 27 gem 'spring', '2.0.2' 28 gem 'spring-watcher-listen', '2.0.1' 29end 30 31group :production do 32 gem 'pg', '0.20.0' 33end 34 35 36# Windows does not include zoneinfo files, so bundle the tzinfo-data gem 37gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
$bundle install --without production $git commit -a -m "Update Gemfile for Heroke" $heroku login $heroku keys:add $heroku create $git push heroku master $heroku open

を実行したら解決しました。

ただ、この状態でpushすると、

fatal: repository 'https://git.heroku.com/xxx.git/' not found

と怒られたので、新しく作ったプロジェクトの名前をブラウザ上でxxxに変更しました。

*もしかすると、

group :production do gem 'pg', '0.20.0' end

を追加前はSublime, 追加時はvimで操作していたことが原因かもしれません。
失礼しました。

投稿2018/12/05 09:36

編集2018/12/05 09:41
tra

総合スコア10

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問