LoginSignup
26
16

More than 3 years have passed since last update.

Herokuへデプロイした時に「The page you were looking for doesn't exist. 」エラーが出る

Posted at

事象

Railsでアプリを作って、動作確認も問題なし!
「さぁHerokuにデプロイ!」と思い、「git push heroku master」を実施。

デプロイされたアプリをherokuのURLを開くと下記のエラーが出た・・・

スクリーンショット 2019-07-07 16.37.45.png

The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.

If you are the application owner check the logs for more information.

ターミナル上でもデプロイ時にエラーが出ておらず原因が不明。

原因

ググってみると、どうやらroutes.rbにroot(URLのトップ)にアクセスした際に表示するページが設定されていないのが問題っぽい。

参考記事
http://mozuzaru.hatenablog.com/entry/2018/03/10/204643

解決方法

routes.rb
Rails.application.routes.draw do
    # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

    root  'users#index'  #この1行を追加

    #ユーザー一覧を表示
    get '/users', to: 'users#index'
    #新規投稿(登録画面)に遷移
    get '/users/new', to: 'users#new'
    #投稿されたデータを受け取る
    post '/users', to: 'users#create'

    #投稿されてデータを編集する画面に行く
    get '/users/:id/edit', to: 'users#edit'

    #編集完了画面に遷移
    patch 'users/:id', to: 'users#update'

    # 投稿の削除を実施する
    delete '/users/:id', to:'users#destroy'
end

root 'users#index'を追加して、再度デプロイしたらHeroku上でも見れるようになったー!
やったね!!
スクリーンショット 2019-07-07 16.45.48.png

26
16
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
26
16