前提・実現したいこと
ログインして、homeに遷移させたい
発生している問題・エラーメッセージ
deviseを実装し、ログインしたいと思ったらhomeに遷移されず、ログインページにリダイレクトされてしまいます。
下記はTerminal上のエラーです。
下記が原因ではないかと考えています。
Started POST "/users/sign_in" for 221.189.157.2 at 2021-08-06 07:05:01 +0000 Cannot render console from 221.189.157.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC ↳ /home/ec2-user/.rvm/gems/ruby-2.6.3/gems/activerecord-5.2.6/lib/active_record/log_subscriber.rb:98 Processing by Users::SessionsController#create as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"zoIuNn+ggYBvgvUEriXEqFtUrVUDjvYigxdXCTmsLgDRTYEwWkTd7tA6vydLrXtF1v/id6lDpS0isD2AKqrKTg==", "user"=>{"name"=>"test2", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Log in"} Completed 401 Unauthorized in 8ms (ActiveRecord: 0.0ms)
該当のソースコード
ApplicationController
1class ApplicationController < ActionController::Base 2 before_action :configure_permitted_parameters, if: :devise_controller? 3 4 5 def after_sign_in_path_for(resource) 6 public_home_path(resource) 7 end 8 9 protected 10 11 def configure_permitted_parameters 12 devise_parameter_sanitizer.permit(:sign_up, keys: [:name]) 13 end 14end 15
route
1Rails.application.routes.draw do 2 3 4 root to: "public/homes#top" 5 get 'public/help' => 'public/homes#help' 6 get 'public/home' => 'public/homes#home' 7 8 devise_for :users, controllers: { 9 sessions: 'users/sessions', 10 passwords: 'users/passwords', 11 registrations: 'users/registrations' 12} 13 14 devise_for :admins, controllers: { 15 sessions: 'admins/sessions', 16 passwords: 'admins/passwords', 17 registrations: 'admins/registrations' 18} 19 20 resources :articles 21 22 23end 24
new
1<div class = "container"> 2 3 <h2>Log in</h2> 4 5 <%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %> 6 7 <div class="field"> 8 <%= f.label :name %><br /> 9 <%= f.text_field :name, autofocus: true, autocomplete: "name" %> 10 </div> 11 12 13 <div class="field"> 14 <%= f.label :password %><br /> 15 <%= f.password_field :password, autocomplete: "current-password" %> 16 </div> 17 18 <% if devise_mapping.rememberable? %> 19 <div class="field"> 20 <%= f.check_box :remember_me %> 21 <%= f.label :remember_me %> 22 </div> 23 <% end %> 24 25 <div class="actions"> 26 <%= f.submit "Log in" %> 27 </div> 28 <% end %> 29 30 <%= render "devise/shared/links" %> 31 32</div>
SessionController
1# frozen_string_literal: true 2 3class Users::SessionsController < Devise::SessionsController 4 # before_action :configure_sign_in_params, only: [:create] 5 6 # GET /resource/sign_in 7 # def new 8 # super 9 # end 10 11 # POST /resource/sign_in 12 # def create 13 # super 14 # end 15 16 # DELETE /resource/sign_out 17 # def destroy 18 # super 19 # end 20 21 # protected 22 23 # If you have extra params to permit, append them to the sanitizer. 24 # def configure_sign_in_params 25 # devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute]) 26 # end 27end 28
試したこと
テラテイルの過去記事等、ネットの情報を頼りに、いろいろ試してみましたが、ログインだけができませんでした。
回答1件
あなたの回答
tips
プレビュー