質問編集履歴
1
コードを画像から変更しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -10,14 +10,114 @@
|
|
10
10
|
|
11
11
|
|
12
12
|
|
13
|
-
|
13
|
+
```userrb
|
14
14
|
|
15
|
+
def self.find_for_oauth(auth)
|
16
|
+
|
15
|
-
|
17
|
+
user = User.where(uid: auth.uid, provider: auth.provider).first
|
16
18
|
|
17
19
|
|
18
20
|
|
21
|
+
user ||= User.create(
|
22
|
+
|
23
|
+
uid: auth.uid,
|
24
|
+
|
25
|
+
provider: auth.provider,
|
26
|
+
|
27
|
+
name: auth.info.name,
|
28
|
+
|
29
|
+
profile: set_profile(auth),
|
30
|
+
|
31
|
+
email: set_email(auth),
|
32
|
+
|
19
|
-
|
33
|
+
password: Devise.friendly_token[0, 20]
|
34
|
+
|
35
|
+
)
|
36
|
+
|
37
|
+
user.image.attach(auth.info.image)
|
38
|
+
|
39
|
+
user
|
40
|
+
|
41
|
+
end
|
20
42
|
|
21
43
|
|
22
44
|
|
45
|
+
class << self
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
def set_email(auth)
|
52
|
+
|
53
|
+
auth.info.email || "#{auth.uid}-#{auth.provider}@example.com"
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
def set_profile(auth)
|
60
|
+
|
61
|
+
auth.info.description
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
```
|
68
|
+
|
69
|
+
ここでのuser.image.attach(auth.info.image)の部分が、attachをしようとしてうまく行かずに詰まっている部分です。
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
```applicationcontroller
|
74
|
+
|
75
|
+
# frozen_string_literal: true
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
class ApplicationController < ActionController::Base
|
80
|
+
|
81
|
+
before_action :configure_permitted_parameters, if: :devise_controller?
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
def after_sign_in_path_for(resource)
|
86
|
+
|
87
|
+
user_path(resource)
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
def after_sign_out_path_for(_resource)
|
94
|
+
|
95
|
+
root_path
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
def configure_permitted_parameters
|
102
|
+
|
103
|
+
devise_parameter_sanitizer.permit(:sign_up, keys: [:name])
|
104
|
+
|
105
|
+
devise_parameter_sanitizer.permit(:account_update, keys: %i[name profile image])
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
def search_param
|
112
|
+
|
113
|
+
params.permit(:search)
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
end
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
```
|
122
|
+
|
23
123
|
わかる方がいらっしゃれば、教えていただけるとありがたいです。
|