前提・実現したいこと
railsでsorceryを使ってログイン機能を作成しようとしているのですが、
思うように作れず困っております。
特にエラーも発生していないように見えるのですが、
画面遷移しないでいます。
私が初心者でrails開発を任されている上、社内にも詳しい者がいない状況です。
どうか皆様のお力を拝借できればと思います。
該当のソースコード
Started GET "/login?utf8=%E2%9C%93&authenticity_token=mst4jXA4YTO%2F2Z60HMf19jl3ZZgH0tYhfrMMb73sGKvpXiote7%2FFThLdH2gipdTjxg%2Ff2JquEh5XSPn88XRAIg%3D%3D&email=test%40test.com&password=[FILTERED]&commit=%E3%83%AD%E3%82%B0%E3%82%A4%E3%83%B3" for 10.0.2.2 at 2018-01-29 09:33:07 +0000 Cannot render console from 10.0.2.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255 Processing by SessionsController#new as HTML Parameters: {"utf8"=>"✓", "authenticity_token"=>"mst4jXA4YTO/2Z60HMf19jl3ZZgH0tYhfrMMb73sGKvpXiote7/FThLdH2gipdTjxg/f2JquEh5XSPn88XRAIg==", "email"=>"test@test.com", "password"=>"[FILTERED]", "commit"=>"ログイン"} Rendering sessions/new.html.erb within layouts/application Rendered sessions/new.html.erb within layouts/application (1.3ms) Completed 200 OK in 268ms (Views: 238.2ms | ActiveRecord: 0.0ms)
Rails.application.routes.draw do # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html root :to => 'sessions#new' resources :sessions resources :users, except: [:edit, :index] resources :clients, except: [:show, :new, :edit] resources :schedules, except: [:show, :new, :edit] get 'login' => 'sessions#new', :as => :login post 'logout' => 'sessions#destroy', :as => :logout get 'tops/index' => 'tops#index' get 'clients/index' => 'clients#index' post 'clients/index' => 'clients#index' get 'schedules/index' => 'schedules#index' post 'schedules/index' => 'schedules#index' end
sorcery.rb
1Rails.application.config.sorcery.submodules = [:remember_me] 2Rails.application.config.sorcery.configure do |config| 3 config.user_config do |user| 4 user.username_attribute_names = :email 5 end 6 config.user_class = 'User' 7end
controller
1class SessionsController < ApplicationController 2 3 def new 4 end 5 6 def create 7 user = login(params[:email], params[:password]) 8 if user 9 redirect_back_or_to tops_index_path, notice: "Login successful" 10 else 11 flash.now[:alert] = "Failed to login" 12 render action: 'new' 13 end 14 end 15 16 def destroy 17 logout 18 redirect_to root_path, notice: "Logged out!" 19 end 20 21end 22 23
model
1class User < ApplicationRecord 2 authenticates_with_sorcery! 3 4 5 validates :email, uniqueness: true 6 validates :password, length: { minimum: 6 }, if: -> { new_record? || changes["password"] } 7 validates :password, confirmation: true, if: -> { new_record? || changes["password"] } 8 validates :password_confirmation, presence: true, if: -> { new_record? || changes["password"] } 9end 10
view
1class User < ApplicationRecord 2 authenticates_with_sorcery! 3 4 5 validates :email, uniqueness: true 6 validates :password, length: { minimum: 6 }, if: -> { new_record? || changes["password"] } 7 validates :password, confirmation: true, if: -> { new_record? || changes["password"] } 8 validates :password_confirmation, presence: true, if: -> { new_record? || changes["password"] } 9end 10
試したこと
ルーティングなどいろいろ試してみましたが、
全く前に進めず困り果てております。
補足情報
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-linux]
Rails 5.1.4
centos
MariaDB
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/01/30 03:43