質問編集履歴
5
deviseのバージョンを追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -133,4 +133,5 @@
|
|
133
133
|
|
134
134
|
Windows8.1 64ビット
|
135
135
|
ruby 2.2.6p396
|
136
|
-
Rails 5.0.7
|
136
|
+
Rails 5.0.7
|
137
|
+
devise 4.5.0
|
4
試したことに「Deviseを初期状態に戻すと」を追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -117,8 +117,9 @@
|
|
117
117
|
|
118
118
|
### 試したこと
|
119
119
|
|
120
|
-
helo_controller.rbから「 + @account.current_sign_in_at.to_s」を消
|
120
|
+
helo_controller.rbから「 + @account.current_sign_in_at.to_s」を消し、
|
121
|
+
Deviseを初期状態に戻すとアプリは正常に動作します。
|
121
|
-
|
122
|
+
(ログインできますが、ログイン時刻は表示されません。)
|
122
123
|
|
123
124
|
schema.rbにt.datetime :current_sign_in_atを追記して、
|
124
125
|
マイグレーション(rails db:migrate)をすると、
|
3
誤字の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
3
|
「Ruby on Rails 5 超入門」に沿ってアプリを作成し、
|
4
|
-
ログイン認証後にログイン時刻を表示させ
|
4
|
+
ログイン認証後にログイン時刻を表示させようとしています。
|
5
5
|
Deviseをインストールしましたが、Trackableが組み込まれていなかったので、
|
6
6
|
t.datetime :current_sign_in_atのコメントを外して、
|
7
7
|
deviseに読み込むように記述したのですが、以下のエラーが出ました。
|
2
初心者マークを付けました。
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|
1
ソースコードをMarkdownで見やすくしました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -10,22 +10,19 @@
|
|
10
10
|
|
11
11
|
NoMethodError in Devise::SessionsController#create
|
12
12
|
undefined method `current_sign_in_at' for #<Account:0x0000000c4ad1f0>
|
13
|
-
|
13
|
+
```ruby
|
14
14
|
else
|
15
15
|
match = matched_attribute_method(method.to_s)
|
16
|
-
|
16
|
+
match ? attribute_missing(match, *args, &block) : super ←エラー部分
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
```
|
20
20
|
|
21
21
|
|
22
22
|
### 該当のソースコード
|
23
23
|
|
24
|
-
いげた(#)の前にシングルクォーテション(')が付いていますが、
|
25
|
-
実際のソースコードにはシングルクォーテション(')は付いていません。
|
26
|
-
|
27
24
|
helo_controller.rb
|
28
|
-
|
25
|
+
```ruby
|
29
26
|
class HeloController < ApplicationController
|
30
27
|
layout 'application'
|
31
28
|
before_action :authenticate_account!, only: :login_check
|
@@ -39,43 +36,43 @@
|
|
39
36
|
@msg = 'you logined at: ' + @account.current_sign_in_at.to_s
|
40
37
|
end
|
41
38
|
end
|
39
|
+
```
|
42
|
-
|
40
|
+
--------------
|
43
|
-
|
44
41
|
20180826062337_devise_create_accounts
|
45
|
-
|
42
|
+
```ruby
|
46
|
-
|
43
|
+
# frozen_string_literal: true
|
47
44
|
|
48
45
|
class DeviseCreateAccounts < ActiveRecord::Migration[5.0]
|
49
46
|
def change
|
50
47
|
create_table :accounts do |t|
|
51
|
-
|
48
|
+
## Database authenticatable
|
52
49
|
t.string :email, null: false, default: ""
|
53
50
|
t.string :encrypted_password, null: false, default: ""
|
54
51
|
|
55
|
-
|
52
|
+
## Recoverable
|
56
53
|
t.string :reset_password_token
|
57
54
|
t.datetime :reset_password_sent_at
|
58
55
|
|
59
|
-
|
56
|
+
## Rememberable
|
60
57
|
t.datetime :remember_created_at
|
61
58
|
|
62
|
-
|
59
|
+
## Trackable
|
63
|
-
|
60
|
+
#t.integer :sign_in_count, default: 0, null: false
|
64
|
-
|
61
|
+
t.datetime :current_sign_in_at
|
65
|
-
|
62
|
+
#t.datetime :last_sign_in_at
|
66
|
-
|
63
|
+
#t.string :current_sign_in_ip
|
67
|
-
|
64
|
+
#t.string :last_sign_in_ip
|
68
65
|
|
69
|
-
|
66
|
+
## Confirmable
|
70
|
-
|
67
|
+
# t.string :confirmation_token
|
71
|
-
|
68
|
+
# t.datetime :confirmed_at
|
72
|
-
|
69
|
+
# t.datetime :confirmation_sent_at
|
73
|
-
|
70
|
+
# t.string :unconfirmed_email # Only if using reconfirmable
|
74
71
|
|
75
|
-
|
72
|
+
## Lockable
|
76
|
-
|
73
|
+
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
77
|
-
|
74
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
78
|
-
|
75
|
+
# t.datetime :locked_at
|
79
76
|
|
80
77
|
|
81
78
|
t.timestamps null: false
|
@@ -83,24 +80,25 @@
|
|
83
80
|
|
84
81
|
add_index :accounts, :email, unique: true
|
85
82
|
add_index :accounts, :reset_password_token, unique: true
|
86
|
-
|
83
|
+
# add_index :accounts, :confirmation_token, unique: true
|
87
|
-
|
84
|
+
# add_index :accounts, :unlock_token, unique: true
|
88
85
|
end
|
89
86
|
end
|
87
|
+
```
|
90
|
-
|
88
|
+
--------------
|
91
89
|
|
92
90
|
account.rb
|
93
|
-
|
91
|
+
```ruby
|
94
92
|
class Account < ApplicationRecord
|
95
93
|
'# Include default devise modules. Others available are:
|
96
94
|
'# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
97
95
|
devise :database_authenticatable, :registerable,
|
98
|
-
:recoverable, :rememberable,
|
96
|
+
:recoverable, :rememberable, :trackable, :validatable
|
99
97
|
end
|
98
|
+
```
|
100
|
-
|
99
|
+
--------------
|
101
|
-
|
102
100
|
schema.rb
|
103
|
-
|
101
|
+
```ruby
|
104
102
|
ActiveRecord::Schema.define(version: 20180826062337) do
|
105
103
|
|
106
104
|
create_table "accounts", force: :cascade do |t|
|
@@ -114,7 +112,7 @@
|
|
114
112
|
t.index ["email"], name: "index_accounts_on_email", unique: true
|
115
113
|
t.index ["reset_password_token"], name: "index_accounts_on_reset_password_token", unique: true
|
116
114
|
end
|
117
|
-
|
115
|
+
```
|
118
116
|
|
119
117
|
|
120
118
|
### 試したこと
|