質問編集履歴
1
ご指摘いただいたmodelは変更いたしました。また、一部名前変更しました。現在、トップ画面に遷移してほしいところ、結局ログイン画面のまま遷移できない状況です。
    
        title	
    CHANGED
    
    | 
         
            File without changes
         
     | 
    
        body	
    CHANGED
    
    | 
         @@ -12,11 +12,13 @@ 
     | 
|
| 
       12 
12 
     | 
    
         
             
            ### 該当のソースコード
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
            ```ターミナル
         
     | 
| 
       15 
     | 
    
         
            -
             
     | 
| 
       16 
     | 
    
         
            -
             
     | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
               
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 15 
     | 
    
         
            +
            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
         
     | 
| 
      
 16 
     | 
    
         
            +
            Cannot render console from 10.0.2.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
         
     | 
| 
      
 17 
     | 
    
         
            +
            Processing by SessionsController#new as HTML
         
     | 
| 
      
 18 
     | 
    
         
            +
              Parameters: {"utf8"=>"✓", "authenticity_token"=>"mst4jXA4YTO/2Z60HMf19jl3ZZgH0tYhfrMMb73sGKvpXiote7/FThLdH2gipdTjxg/f2JquEh5XSPn88XRAIg==", "email"=>"test@test.com", "password"=>"[FILTERED]", "commit"=>"ログイン"}
         
     | 
| 
      
 19 
     | 
    
         
            +
              Rendering sessions/new.html.erb within layouts/application
         
     | 
| 
      
 20 
     | 
    
         
            +
              Rendered sessions/new.html.erb within layouts/application (1.3ms)
         
     | 
| 
      
 21 
     | 
    
         
            +
            Completed 200 OK in 268ms (Views: 238.2ms | ActiveRecord: 0.0ms)
         
     | 
| 
       20 
22 
     | 
    
         | 
| 
       21 
23 
     | 
    
         
             
            ```
         
     | 
| 
       22 
24 
     | 
    
         
             
            ```### 該当のソースコード
         
     | 
| 
         @@ -25,17 +27,19 @@ 
     | 
|
| 
       25 
27 
     | 
    
         | 
| 
       26 
28 
     | 
    
         
             
              # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
         
     | 
| 
       27 
29 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
              root :to => ' 
     | 
| 
      
 30 
     | 
    
         
            +
              root :to => 'sessions#new'
         
     | 
| 
       29 
     | 
    
         
            -
              resources : 
     | 
| 
      
 31 
     | 
    
         
            +
              resources :sessions
         
     | 
| 
       30 
32 
     | 
    
         
             
              resources :users, except: [:edit, :index]
         
     | 
| 
       31 
33 
     | 
    
         
             
              resources :clients, except: [:show, :new, :edit]
         
     | 
| 
      
 34 
     | 
    
         
            +
              resources :schedules, except: [:show, :new, :edit]
         
     | 
| 
       32 
35 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
              get 'login' => ' 
     | 
| 
      
 36 
     | 
    
         
            +
              get 'login' => 'sessions#new', :as => :login
         
     | 
| 
       34 
     | 
    
         
            -
              post 'logout' => ' 
     | 
| 
      
 37 
     | 
    
         
            +
              post 'logout' => 'sessions#destroy', :as => :logout
         
     | 
| 
       35 
38 
     | 
    
         
             
              get 'tops/index' => 'tops#index'
         
     | 
| 
       36 
39 
     | 
    
         
             
              get 'clients/index' => 'clients#index'
         
     | 
| 
       37 
40 
     | 
    
         
             
              post 'clients/index' => 'clients#index'
         
     | 
| 
       38 
     | 
    
         
            -
              get 'schedules/index'
         
     | 
| 
      
 41 
     | 
    
         
            +
              get 'schedules/index' => 'schedules#index'
         
     | 
| 
      
 42 
     | 
    
         
            +
              post 'schedules/index' => 'schedules#index'
         
     | 
| 
       39 
43 
     | 
    
         | 
| 
       40 
44 
     | 
    
         | 
| 
       41 
45 
     | 
    
         
             
            end
         
     | 
| 
         @@ -51,59 +55,53 @@ 
     | 
|
| 
       51 
55 
     | 
    
         
             
            end
         
     | 
| 
       52 
56 
     | 
    
         
             
            ```
         
     | 
| 
       53 
57 
     | 
    
         
             
            ```controller
         
     | 
| 
       54 
     | 
    
         
            -
            class  
     | 
| 
      
 58 
     | 
    
         
            +
            class SessionsController < ApplicationController
         
     | 
| 
       55 
     | 
    
         
            -
             
     | 
| 
      
 59 
     | 
    
         
            +
             
     | 
| 
       56 
60 
     | 
    
         
             
              def new
         
     | 
| 
       57 
     | 
    
         
            -
                @user = User.new
         
     | 
| 
       58 
61 
     | 
    
         
             
              end
         
     | 
| 
       59 
62 
     | 
    
         | 
| 
       60 
63 
     | 
    
         
             
              def create
         
     | 
| 
       61 
     | 
    
         
            -
                 
     | 
| 
      
 64 
     | 
    
         
            +
                user = login(params[:email], params[:password])
         
     | 
| 
      
 65 
     | 
    
         
            +
                if user
         
     | 
| 
       62 
66 
     | 
    
         
             
                  redirect_back_or_to tops_index_path, notice: "Login successful"
         
     | 
| 
       63 
67 
     | 
    
         
             
                else
         
     | 
| 
       64 
68 
     | 
    
         
             
                  flash.now[:alert] = "Failed to login"
         
     | 
| 
       65 
     | 
    
         
            -
                   
     | 
| 
      
 69 
     | 
    
         
            +
                  render action: 'new'
         
     | 
| 
       66 
70 
     | 
    
         
             
                end
         
     | 
| 
       67 
71 
     | 
    
         
             
              end
         
     | 
| 
       68 
     | 
    
         
            -
             
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
       69 
73 
     | 
    
         
             
              def destroy
         
     | 
| 
       70 
74 
     | 
    
         
             
                logout
         
     | 
| 
       71 
     | 
    
         
            -
                redirect_to  
     | 
| 
      
 75 
     | 
    
         
            +
                redirect_to root_path, notice: "Logged out!"
         
     | 
| 
       72 
76 
     | 
    
         
             
              end
         
     | 
| 
      
 77 
     | 
    
         
            +
             
     | 
| 
       73 
78 
     | 
    
         
             
            end
         
     | 
| 
       74 
79 
     | 
    
         | 
| 
      
 80 
     | 
    
         
            +
             
     | 
| 
       75 
81 
     | 
    
         
             
            ```
         
     | 
| 
       76 
82 
     | 
    
         
             
            ```model
         
     | 
| 
       77 
83 
     | 
    
         
             
            class User < ApplicationRecord
         
     | 
| 
       78 
84 
     | 
    
         
             
              authenticates_with_sorcery!
         
     | 
| 
       79 
     | 
    
         
            -
              
         
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
      
 86 
     | 
    
         
            +
             
     | 
| 
       82 
     | 
    
         
            -
              validates :email, presence: true
         
     | 
| 
       83 
87 
     | 
    
         
             
              validates :email, uniqueness: true
         
     | 
| 
      
 88 
     | 
    
         
            +
              validates :password, length: { minimum: 6 }, if: -> { new_record? || changes["password"] }
         
     | 
| 
      
 89 
     | 
    
         
            +
              validates :password, confirmation: true, if: -> { new_record? || changes["password"] }
         
     | 
| 
      
 90 
     | 
    
         
            +
              validates :password_confirmation, presence: true, if: -> { new_record? || changes["password"] }
         
     | 
| 
      
 91 
     | 
    
         
            +
            end
         
     | 
| 
       84 
92 
     | 
    
         | 
| 
       85 
     | 
    
         
            -
            end
         
     | 
| 
       86 
93 
     | 
    
         
             
            ```
         
     | 
| 
       87 
94 
     | 
    
         
             
            ```view
         
     | 
| 
       88 
     | 
    
         
            -
            <h1 class="page-title">ログイン画面</h1>
         
     | 
| 
       89 
     | 
    
         
            -
            <fieldset>
         
     | 
| 
       90 
     | 
    
         
            -
              <h1 class="login-box-title">ログイン</h1>
         
     | 
| 
       91 
     | 
    
         
            -
              <form>
         
     | 
| 
       92 
     | 
    
         
            -
                <%= form_tag new_user_session_path, :method => :post, local: true do %>
         
     | 
| 
       93 
     | 
    
         
            -
             
     | 
| 
      
 95 
     | 
    
         
            +
            class User < ApplicationRecord
         
     | 
| 
       94 
     | 
    
         
            -
                  <div class="iconemail"></div>
         
     | 
| 
       95 
     | 
    
         
            -
                  <%= text_field_tag :email, params[:email], :placeholder => "Email", class: "field" %>
         
     | 
| 
       96 
     | 
    
         
            -
                </div>
         
     | 
| 
       97 
     | 
    
         
            -
                <div class="fieldbox">
         
     | 
| 
       98 
     | 
    
         
            -
                  <div class="iconpassword"></div>
         
     | 
| 
       99 
     | 
    
         
            -
                  <%= password_field_tag :crypted_password, params[:crypted_password], :placeholder => "Password", class: "field" %>
         
     | 
| 
       100 
     | 
    
         
            -
                </div>
         
     | 
| 
       101 
     | 
    
         
            -
                <%= submit_tag "ログイン", :class => "login-submit" %>
         
     | 
| 
       102 
     | 
    
         
            -
                <%= link_to "Signup", tops_index_path %>
         
     | 
| 
       103 
     | 
    
         
            -
              <% end %>
         
     | 
| 
       104 
     | 
    
         
            -
            </form>
         
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
      
 96 
     | 
    
         
            +
              authenticates_with_sorcery!
         
     | 
| 
       106 
97 
     | 
    
         | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
              validates :email, uniqueness: true
         
     | 
| 
      
 100 
     | 
    
         
            +
              validates :password, length: { minimum: 6 }, if: -> { new_record? || changes["password"] }
         
     | 
| 
      
 101 
     | 
    
         
            +
              validates :password, confirmation: true, if: -> { new_record? || changes["password"] }
         
     | 
| 
      
 102 
     | 
    
         
            +
              validates :password_confirmation, presence: true, if: -> { new_record? || changes["password"] }
         
     | 
| 
      
 103 
     | 
    
         
            +
            end
         
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
       107 
105 
     | 
    
         
             
            ```
         
     | 
| 
       108 
106 
     | 
    
         
             
            ### 試したこと
         
     | 
| 
       109 
107 
     | 
    
         |