現在の状態説明
railsソースをHerokuにデプロイ後にエラーが出る
このエラーを解消したいです。
初投稿でわかりにくい部分があると思いますが質問してもらえればすぐに答えます!
railsでdeviseを使ったユーザーログイン機能を実装してアプリを作成しました,
ローカル環境でエラーがないことを確認した後
Herokuにデプロイしたら以下のようなメッセージが出力されました。
We're sorry, but something went wrong. If you are the application owner check the logs for more information.
エラーログの確認
logファイルのdevelopment.logを確認すると以下のように記載されていました。
[1m[35m (16.1ms)[0m [1m[35mSET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483[0m [1m[35m (8.6ms)[0m [1m[35mCREATE DATABASE `happy_hobby_development` DEFAULT CHARACTER SET `utf8`[0m [1m[35m (0.4ms)[0m [1m[35mSET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483[0m [1m[35m (2.0ms)[0m [1m[35mCREATE DATABASE `happy_hobby_test` DEFAULT CHARACTER SET `utf8`[0m Started GET "/" for ::1 at 2021-01-04 14:07:22 +0900 [1m[35m (21.8ms)[0m [1m[35mSET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483[0m Processing by CommunitiesController#index as HTML Rendering communities/index.html.erb within layouts/application Rendered communities/index.html.erb within layouts/application (Duration: 2.9ms | Allocations: 375) [Webpacker] Compiling... [Webpacker] Compiled all packs in /Users/kazumasa/projects/happy_hobby/public/packs [Webpacker] Hash: 76145d9ce4575ebaa29b Version: webpack 4.44.2 Time: 2095ms Built at: 2021/01/04 14:07:27 Asset Size Chunks Chunk Names js/application-c229f7c7014cf8c8d494.js 124 KiB application [emitted] [immutable] application js/application-c229f7c7014cf8c8d494.js.map 139 KiB application [emitted] [dev] application manifest.json 364 bytes [emitted] Entrypoint application = js/application-c229f7c7014cf8c8d494.js js/application-c229f7c7014cf8c8d494.js.map [./app/javascript/channels sync recursive _channel.js$] ./app/javascript/channels sync _channel.js$ 160 bytes {application} [built] [./app/javascript/channels/index.js] 211 bytes {application} [built] [./app/javascript/packs/application.js] 749 bytes {application} [built] [./node_modules/webpack/buildin/module.js] (webpack)/buildin/module.js 552 bytes {application} [built] + 3 hidden modules Completed 200 OK in 5490ms (Views: 5472.4ms | ActiveRecord: 0.0ms | Allocations: 1541338) Started GET "/" for ::1 at 2021-01-04 14:35:45 +0900 [1m[35m (0.4ms)[0m [1m[35mSET NAMES utf8, @@SESSION.sql_mode = CONCAT(CONCAT(@@sql_mode, ',STRICT_ALL_TABLES'), ',NO_AUTO_VALUE_ON_ZERO'), @@SESSION.sql_auto_is_null = 0, @@SESSION.wait_timeout = 2147483[0m Processing by CommunitiesController#index as HTML Rendering communities/index.html.erb within layouts/application Rendered communities/_header.html.erb (Duration: 253.2ms | Allocations: 77664) Rendered communities/index.html.erb within layouts/application (Duration: 255.5ms | Allocations: 77971) Completed 500 Internal Server Error in 264ms (ActiveRecord: 0.0ms | Allocations: 79207) ActionView::Template::Error (undefined method `user_signed_in?' for #<#<Class:0x00007fab47c7ea58>:0x00007fab47c8ff88>): 6: </ul> 7: <ul class='lists-right'> 8: <%# ログインの有無で表示変更%> 9: <% if user_signed_in? %> 10: <li><%= link_to current_user.nickname, "#", class: "user-nickname" %></li> 11: <li><%= link_to 'ログアウト', destroy_user_session_path, method: :delete, class: "logout" %></li> 12: <% else %> app/views/communities/_header.html.erb:9 app/views/communities/index.html.erb:1 Started GET "/" for ::1 at 2021-01-04 14:36:42 +0900 Processing by CommunitiesController#index as HTML Rendering communities/index.html.erb within layouts/application Rendered communities/_header.html.erb (Duration: 162.3ms | Allocations: 74882) Rendered communities/index.html.erb within layouts/application (Duration: 163.0ms | Allocations: 75387) Completed 500 Internal Server Error in 165ms (ActiveRecord: 0.0ms | Allocations: 76072) ActionView::Template::Error (undefined method `user_signed_in?' for #<#<Class:0x00007fab47c7ea58>:0x00007fab42d00b48>): 6: </ul> 7: <ul class='lists-right'> 8: <li><%= link_to 'ログイン', new_user_session_path, class: "login" %></li> 9: <li><%= link_to '新規登録', new_user_registration_path, class: "sign-up" %></li> 10: </ul> 11: </div> 12: </header> app/views/communities/_header.html.erb:9 app/views/communities/index.html.erb:1 Started GET "/" for ::1 at 2021-01-04 14:37:14 +0900 Processing by CommunitiesController#index as HTML Rendering communities/index.html.erb within layouts/application Rendered communities/_header.html.erb (Duration: 1.1ms | Allocations: 239) Rendered communities/index.html.erb within layouts/application (Duration: 2.5ms | Allocations: 532) [Webpacker] Everything's up-to-date. Nothing to do Completed 200 OK in 39ms (Views: 37.6ms | ActiveRecord: 0.0ms | Allocations: 8182)
該当のソースコード
エラー内容を確認したところ[_header.html.erb]のファイルの
user_signed_in?の部分が怪しいと考えたのですが
どこがおかしいのか全くわかりませんでした。
html
1<header class='top-page-header'> 2 <h1 class='title'>Happy Hobby</h1> 3 <div class='menu'> 4 <ul class='lists-left'> 5 <li><%= link_to '趣味診断', hobbies_path, class: "hobby" %></li> 6 </ul> 7 <ul class='lists-right'> 8 <% if user_signed_in? %> 9 <li><%= link_to current_user.nickname, "#", class: "user-nickname" %></li> 10 <li><%= link_to 'コミュニティ作成', new_community_path, class: "make-community" %></li> 11 <li><%= link_to 'ログアウト', destroy_user_session_path, method: :delete, class: "logout" %></li> 12 <% else %> 13 <li><%= link_to 'ログイン', new_user_session_path, class: "login" %></li> 14 <li><%= link_to '新規登録', new_user_registration_path, class: "sign-up" %></li> 15 <% end %> 16 </ul> 17 </div> 18</header>
試したこと
不要なコメントを全て削除
deviseのGEMのインストール確認
routes.rbのファイルにdevise_for :usersの記載確認
補足情報(FW/ツールのバージョンなど)
railsのバージョンは6.0.0です
情報は以上です。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。