質問編集履歴
1
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,4 +9,47 @@
|
|
9
9
|
def bookmark(board)
|
10
10
|
bookmark_boards << board
|
11
11
|
end
|
12
|
+
```
|
13
|
+
|
14
|
+
```
|
15
|
+
class User < ApplicationRecord
|
16
|
+
authenticates_with_sorcery!
|
17
|
+
|
18
|
+
validates :password, length: { minimum: 3 }, if: -> { new_record? || changes[:crypted_password] }
|
19
|
+
validates :password, confirmation: true, if: -> { new_record? || changes[:crypted_password] }
|
20
|
+
validates :password_confirmation, presence: true, if: -> { new_record? || changes[:crypted_password] }
|
21
|
+
|
22
|
+
validates :email, uniqueness: true
|
23
|
+
validates :email, presence: true
|
24
|
+
validates :first_name, presence: true, length: { maximum: 255 }
|
25
|
+
validates :last_name, presence: true, length: { maximum: 255 }
|
26
|
+
validates :reset_password_token, uniqueness: { scope: :user }, allow_nil: true
|
27
|
+
|
28
|
+
has_many :boards, dependent: :destroy
|
29
|
+
has_many :comments, dependent: :destroy
|
30
|
+
has_many :bookmarks, dependent: :destroy
|
31
|
+
has_many :bookmark_boards, through: :bookmarks, source: :board
|
32
|
+
mount_uploader :avatar, AvatarUploader
|
33
|
+
enum role:
|
34
|
+
{
|
35
|
+
general: 0,
|
36
|
+
admin: 1
|
37
|
+
}
|
38
|
+
def own?(object)
|
39
|
+
id == object.user_id
|
40
|
+
end
|
41
|
+
|
42
|
+
def bookmark(board)
|
43
|
+
bookmark_boards << board
|
44
|
+
end
|
45
|
+
|
46
|
+
def unbookmark(board)
|
47
|
+
bookmark_boards.destroy(board)
|
48
|
+
end
|
49
|
+
|
50
|
+
def bookmark?(board)
|
51
|
+
bookmark_boards.include?(board)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
12
55
|
```
|