ユーザー管理機能のログイン機能を実装しようとしており、新規登録後ログアウトしてから登録した情報のemailとパスワードを正しく入力してもinvalid email or passwordと表示されログイン出来ない。
application_controller.rbにdeviseのストロングパラメーターを用いてsign_upとsign_in時のemailとpasswordをpermitしてます。
DBには登録情報が保存されているが、何度ログインを試みてもログインすることが出来ません。
どなたかもし宜しければご教授お願い致します。
application.rb
class ApplicationController < ActionController::Base before_action :configure_permitted_parameters, if: :devise_controller? private def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:nickname, :email, :encrypted_password, :last_name, :first_name, :last_name_kana, :first_name_kana, :birth_day]) devise_parameter_sanitizer.permit(:sign_in, keys: [:email, :encrypted_password]) end end
items.controller.rb
class ItemsController < ApplicationController def index end def new end end
user.rb
class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable has_many :items has_many :purchases with_options presence: true do validates :nickname validates :birth_day validates :email, uniqueness: { case_sensitive: false } validates :password, format: { with: /\A[a-z0-9]+\z/i, message: "英数字文字6以上"} with_options format: { with: /\A[ぁ-んァ-ン一-龥]+\z/, message: '全角文字を使用してください' } do validates :first_name validates :last_name end with_options format: { with: /\A[ァ-ヶー-]+\z/, message: "全角カタカナを使用してください" } do validates :first_name_kana validates :last_name_kana end end end
sessions/new.html.erb
<%= render "shared/second-header"%> <%= form_with class: 'registration-main', local: true do |f| %> <div class='form-wrap'> <div class='form-header'> <h1 class='form-header-text'> 会員情報入力 </h1> </div> <div class='login-flash-message'> <%= flash[:notice] %> <%= flash[:alert] %> </div> <div class="form-group"> <div class='form-text-wrap'> <label class="form-text">メールアドレス</label> <span class="indispensable">必須</span> </div> <%= f.email_field :email, class:"input-default", id:"email", placeholder:"PC・携帯どちらでも可", autofocus: true %> </div> <div class="form-group"> <div class='form-text-wrap'> <label class="form-text">パスワード</label> <span class="indispensable">必須</span> </div> <%= f.password_field :encrypted_password, class:"input-default", id:"encrypted_password", placeholder:"" %> </div> <div class='login-btn'> <%= f.submit "ログイン" ,class:"login-red-btn" %> </div> </div> <% end %> <%= render "shared/second-footer"%>
その他必要なファイル等あればなんなりとお申し付けください。
どうぞよろしくお願い致します。
Rails 6.0.3.4
ruby 2.6.5
あなたの回答
tips
プレビュー