diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 56fccf9..fc6f22c 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,7 +1,8 @@ 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]) if session[:user_id].present? + end helper_method :current_user diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 26b5e71..3abc54b 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&.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 %>