質問編集履歴
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -21,3 +21,89 @@
|
|
21
21
|
end
|
22
22
|
|
23
23
|
```
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
```
|
28
|
+
|
29
|
+
class User < ApplicationRecord
|
30
|
+
|
31
|
+
authenticates_with_sorcery!
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
validates :password, length: { minimum: 3 }, if: -> { new_record? || changes[:crypted_password] }
|
36
|
+
|
37
|
+
validates :password, confirmation: true, if: -> { new_record? || changes[:crypted_password] }
|
38
|
+
|
39
|
+
validates :password_confirmation, presence: true, if: -> { new_record? || changes[:crypted_password] }
|
40
|
+
|
41
|
+
|
42
|
+
|
43
|
+
validates :email, uniqueness: true
|
44
|
+
|
45
|
+
validates :email, presence: true
|
46
|
+
|
47
|
+
validates :first_name, presence: true, length: { maximum: 255 }
|
48
|
+
|
49
|
+
validates :last_name, presence: true, length: { maximum: 255 }
|
50
|
+
|
51
|
+
validates :reset_password_token, uniqueness: { scope: :user }, allow_nil: true
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
has_many :boards, dependent: :destroy
|
56
|
+
|
57
|
+
has_many :comments, dependent: :destroy
|
58
|
+
|
59
|
+
has_many :bookmarks, dependent: :destroy
|
60
|
+
|
61
|
+
has_many :bookmark_boards, through: :bookmarks, source: :board
|
62
|
+
|
63
|
+
mount_uploader :avatar, AvatarUploader
|
64
|
+
|
65
|
+
enum role:
|
66
|
+
|
67
|
+
{
|
68
|
+
|
69
|
+
general: 0,
|
70
|
+
|
71
|
+
admin: 1
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
def own?(object)
|
76
|
+
|
77
|
+
id == object.user_id
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
def bookmark(board)
|
84
|
+
|
85
|
+
bookmark_boards << board
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
def unbookmark(board)
|
92
|
+
|
93
|
+
bookmark_boards.destroy(board)
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
def bookmark?(board)
|
100
|
+
|
101
|
+
bookmark_boards.include?(board)
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
```
|