undefined method `logged_in?

実現したいこと

現在Rubyにて個人開発を行っています。
sorceryを使ってログイン機能を実装したいのですが,エラーを解決したいです。

発生している問題・分からないこと

Image from Gyazo

エラーメッセージ

error

1NoMethodError in Tops#index 2Showing /horror_burn/app/views/layouts/application.html.erb where line #13 raised: 3 4undefined method `logged_in?' for #<ActionView::Base:0x00000000281400> 5Extracted source (around line #13): 611 712 813 914 1015 1116 12 13 </head> 14 <body class="flex flex-col min-h-screen bg-zinc-900"> 15 <% if logged_in? %> 16 <%= render 'shared/header' %> 17 <% else %> 18 <%= render 'shared/before_login_header' %> 19 20Rails.root: /horror_burn 21 22Application Trace | Framework Trace | Full Trace 23app/views/layouts/application.html.erb:13 24

該当のソースコード

application_controller.rb

1class ApplicationController < ActionController::Base 2 add_flash_types :success, :info, :warning, :danger 3 before_action :require_login 4 5 private 6 7 def not_authenticated 8 redirect_to login_path, danger: 'ログインしてください' 9 end 10end 11

app/views/layouts/application.html.erb

1<!DOCTYPE html> 2<html> 3 <head> 4 <title>HorrorBurn</title> 5 <meta name="viewport" content="width=device-width,initial-scale=1"> 6 <%= csrf_meta_tags %> 7 <%= csp_meta_tag %> 8 9 <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %> 10 <%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %> 11 </head> 12 <body class="flex flex-col min-h-screen bg-zinc-900"> 13 <% if logged_in? %> 14 <%= render 'shared/header' %> 15 <% else %> 16 <%= render 'shared/before_login_header' %> 17 <% end %> 18 <%= render 'shared/flash_message' %> 19 <%= yield %> 20 <%= render 'shared/footer' %> 21 </body> 22</html> 23

user_controller.rb

1class UsersController < ApplicationController 2 skip_before_action :require_login, only: %i[new create] 3 4 def new 5 @user = User.new 6 end 7 8 def create 9 @user = User.new(user_params) 10 if @user.save 11 redirect_to login_path, success: t('.success') 12 else 13 flash.now[:danger] = t('.fail') 14 render :new, status: :unprocessable_entity 15 end 16 end 17 18 private 19 20 def user_params 21 params.require(:user).permit(:email, :password, :password_confirmation, :name) 22 end 23end 24

user_sessions_contoller.rb

1class UserSessionsController < ApplicationController 2 skip_before_action :require_login, only: %i[new create] 3 4 def new; end 5 6 def create; end 7 8 def destroy; end 9end 10

試したこと・調べたこと

上記の詳細・結果

https://teratail.com/questions/270215
https://teratail.com/questions/342841

上記サイト拝見し,訂正してみたのですが変化がなく,ご教示いただけると幸いです。

補足

特になし

コメントを投稿

0 コメント