質問編集履歴
2
change
test
CHANGED
File without changes
|
test
CHANGED
@@ -2,113 +2,7 @@
|
|
2
2
|
|
3
3
|
**undefined method `has_attached_file' for #<Class:0x007fe78b215780>**
|
4
4
|
|
5
|
-
```ここに言語を入力
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
//has_attached_file :avatar, styles: {//
|
12
|
-
|
13
|
-
thumb: '100x100>',
|
14
|
-
|
15
|
-
square: '200x200#',
|
16
|
-
|
17
|
-
medium: '300x300>'
|
18
|
-
|
19
|
-
//コメントアウトをしたとこがエラーです!
|
20
|
-
|
21
|
-
```
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
rails 5
|
26
|
-
|
27
|
-
gem "paperclip"
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
```
|
32
|
-
|
33
|
-
//models/user.rb
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
class User < ApplicationRecord
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
validates :name, presence: true,uniqueness: true, length: { maximum: 50 }
|
42
|
-
|
43
|
-
validates :email, {presence: true, uniqueness: true}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
has_many :questions
|
48
|
-
|
49
|
-
has_many :answers
|
50
|
-
|
51
|
-
has_many :likes
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
# This method associates the attribute ":avatar" with a file attachment
|
56
|
-
|
57
|
-
has_attached_file :avatar, styles: {
|
58
|
-
|
59
|
-
thumb: '100x100>',
|
60
|
-
|
61
|
-
square: '200x200#',
|
62
|
-
|
63
|
-
medium: '300x300>'
|
64
|
-
|
65
|
-
}
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
# Validate the attached image is image/jpg, image/png, etc
|
70
|
-
|
71
|
-
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
def self.from_omniauth(auth)
|
78
|
-
|
79
|
-
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
|
80
|
-
|
81
|
-
user.email = auth.info.email
|
82
|
-
|
83
|
-
user.password = Devise.friendly_token[0,20]
|
84
|
-
|
85
|
-
user.name = auth.info.name # assuming the user model has a name
|
86
|
-
|
87
|
-
user.image = "http://graph.facebook.com/#{auth.uid}/picture?type=large" # assuming the user model has an image
|
88
|
-
|
89
|
-
# If you are using confirmable and the provider(s) you use validate emails,
|
90
|
-
|
91
|
-
# uncomment the line below to skip the confirmation emails.
|
92
|
-
|
93
|
-
# user.skip_confirmation!
|
94
|
-
|
95
|
-
end
|
96
|
-
|
97
|
-
end
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
def questions
|
102
|
-
|
103
|
-
return Question.where(user_id: self.id)
|
104
|
-
|
105
|
-
end
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
```
|
112
6
|
|
113
7
|
|
114
8
|
|
1
add model
test
CHANGED
File without changes
|
test
CHANGED
@@ -28,6 +28,90 @@
|
|
28
28
|
|
29
29
|
|
30
30
|
|
31
|
+
```
|
32
|
+
|
33
|
+
//models/user.rb
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
class User < ApplicationRecord
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
validates :name, presence: true,uniqueness: true, length: { maximum: 50 }
|
42
|
+
|
43
|
+
validates :email, {presence: true, uniqueness: true}
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
has_many :questions
|
48
|
+
|
49
|
+
has_many :answers
|
50
|
+
|
51
|
+
has_many :likes
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
# This method associates the attribute ":avatar" with a file attachment
|
56
|
+
|
57
|
+
has_attached_file :avatar, styles: {
|
58
|
+
|
59
|
+
thumb: '100x100>',
|
60
|
+
|
61
|
+
square: '200x200#',
|
62
|
+
|
63
|
+
medium: '300x300>'
|
64
|
+
|
65
|
+
}
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
# Validate the attached image is image/jpg, image/png, etc
|
70
|
+
|
71
|
+
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
def self.from_omniauth(auth)
|
78
|
+
|
79
|
+
where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
|
80
|
+
|
81
|
+
user.email = auth.info.email
|
82
|
+
|
83
|
+
user.password = Devise.friendly_token[0,20]
|
84
|
+
|
85
|
+
user.name = auth.info.name # assuming the user model has a name
|
86
|
+
|
87
|
+
user.image = "http://graph.facebook.com/#{auth.uid}/picture?type=large" # assuming the user model has an image
|
88
|
+
|
89
|
+
# If you are using confirmable and the provider(s) you use validate emails,
|
90
|
+
|
91
|
+
# uncomment the line below to skip the confirmation emails.
|
92
|
+
|
93
|
+
# user.skip_confirmation!
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
def questions
|
102
|
+
|
103
|
+
return Question.where(user_id: self.id)
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
```
|
112
|
+
|
113
|
+
|
114
|
+
|
31
115
|
has_attached_fileはrails5では対応されていないのでしょうか?
|
32
116
|
|
33
117
|
また、解決法などがありましたら、教えてください!
|