質問編集履歴
2
post testの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -65,3 +65,21 @@
|
|
65
65
|
has_many :posts,dependent: :destroy
|
66
66
|
|
67
67
|
```
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
```
|
72
|
+
|
73
|
+
def setup
|
74
|
+
|
75
|
+
@user = User.new(name: "Example User", mail_address: "user@example.com",
|
76
|
+
|
77
|
+
password: "foobar", password_confirmation: "foobar")
|
78
|
+
|
79
|
+
@post = Post.new(content: "example", user_id: @user.id , user_name: "example")
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
```
|
1
関連付けのコードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -35,3 +35,33 @@
|
|
35
35
|
end
|
36
36
|
|
37
37
|
```
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
関連付けコード
|
42
|
+
|
43
|
+
``````
|
44
|
+
|
45
|
+
post.rb
|
46
|
+
|
47
|
+
class Post < ApplicationRecord
|
48
|
+
|
49
|
+
belongs_to :user
|
50
|
+
|
51
|
+
validates :content, presence: true,length: { maximum: 200 }
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
```
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
``````
|
60
|
+
|
61
|
+
user.rb
|
62
|
+
|
63
|
+
class User < ApplicationRecord
|
64
|
+
|
65
|
+
has_many :posts,dependent: :destroy
|
66
|
+
|
67
|
+
```
|