From 01ad3366a4604d9ac61123dad4fbcb53c1363f6d Mon Sep 17 00:00:00 2001 From: MiyazakiAkari Date: Sun, 23 Apr 2023 16:44:56 +0900 Subject: [PATCH 1/3] bug_fix --- app/controllers/application_controller.rb | 6 ++++-- app/controllers/sessions_controller.rb | 4 ++-- app/views/posts/_form.html.erb | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 56fccf9..643343f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,12 +1,14 @@ class ApplicationController < ActionController::Base def current_user - @current_user ||= User.find_by(id: session[:id]) if session[:user_id].present? + @current_user ||= User.find_by(id: session[:user_id]) end helper_method :current_user def require_login - redirect_to new_session_path, alert: 'ログインしてください' unless current_user + if !current_user.nil? + redirect_to new_session_path, alert: 'ログインしてください' unless current_user + end end end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 26b5e71..a1f0a20 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -3,8 +3,8 @@ class SessionsController < ApplicationController def new; end def create - user = User.find_by(email: params[:email]) - if user&.authenticate(params[:password]) + user = User.find_by(email: params[:session][:email]) + if user && user.authenticate(params[:session][:password]) session[:user_id] = user.id redirect_to posts_path, notice: 'ログインしました' else diff --git a/app/views/posts/_form.html.erb b/app/views/posts/_form.html.erb index f943aad..16c95aa 100644 --- a/app/views/posts/_form.html.erb +++ b/app/views/posts/_form.html.erb @@ -13,7 +13,7 @@
<%= form.label :title, style: "display: block" %> - <%= form.text_field :titlee %> + <%= form.text_field :title %>
From a96031d3a8ec4460ff664bea1a4e9225d4b5ccbc Mon Sep 17 00:00:00 2001 From: MiyazakiAkari Date: Mon, 24 Apr 2023 21:01:37 +0900 Subject: [PATCH 2/3] bug_fix --- app/controllers/application_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 643343f..e5c5a8f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -8,7 +8,7 @@ def current_user def require_login if !current_user.nil? - redirect_to new_session_path, alert: 'ログインしてください' unless current_user + redirect_to new_session_path, alert: 'ログインしてください' end end end From ff4d1ee3fcee60ecbbcf43571ec9ff6f5aca1cb0 Mon Sep 17 00:00:00 2001 From: MiyazakiAkari Date: Tue, 25 Apr 2023 06:04:44 +0900 Subject: [PATCH 3/3] bug_fix --- app/controllers/application_controller.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index e5c5a8f..8640bb8 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,14 +1,12 @@ class ApplicationController < ActionController::Base def current_user - @current_user ||= User.find_by(id: session[:user_id]) + @current_user ||= User.find_by(id: session[:user_id]) if session[:user_id].present? end helper_method :current_user def require_login - if !current_user.nil? - redirect_to new_session_path, alert: 'ログインしてください' - end + redirect_to new_session_path, alert: 'ログインしてください' unless current_user end end