質問編集履歴
1
post,character,characters_postモデルのコードを追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -66,6 +66,30 @@
|
|
66
66
|
end
|
67
67
|
end
|
68
68
|
```
|
69
|
+
5,モデル
|
70
|
+
```models/post.rb
|
71
|
+
has_many :characters_posts
|
72
|
+
has_many :characters, through: :characters_posts
|
73
|
+
belongs_to :user
|
74
|
+
|
75
|
+
validates :date, presence: true
|
76
|
+
validates :title, presence: true
|
77
|
+
validates :reason, presence: true
|
78
|
+
validates :experiment, presence: true
|
79
|
+
validates :review, presence: true
|
80
|
+
validates :setting, inclusion: {in: [true, false]}
|
81
|
+
```
|
82
|
+
```models/character.rb
|
83
|
+
belongs_to :user
|
84
|
+
validates :name, presence: true, uniqueness: true
|
85
|
+
|
86
|
+
has_many :characters_posts
|
87
|
+
has_many :posts, through: :characters_posts
|
88
|
+
```
|
89
|
+
```models/characters_post.rb
|
90
|
+
belongs_to :character
|
91
|
+
belongs_to :post
|
92
|
+
```
|
69
93
|
|
70
94
|
### 試したこと
|
71
95
|
現在表示されているpostのidと同じpost_idを持つデータがcharacters_postsテーブルに存在するかどうかを確かめればよいと考え、<% if t.present? %>という条件式を追加しました。
|