質問編集履歴
1
コントローラー、モデル、マイグレーションファイルの加筆
title
CHANGED
File without changes
|
body
CHANGED
@@ -44,7 +44,7 @@
|
|
44
44
|
###groupテーブルのみ保存された時のコントローラーとview
|
45
45
|
|
46
46
|
```controler
|
47
|
-
#
|
47
|
+
#Groupsのコントローラー
|
48
48
|
class GroupsController < ApplicationController
|
49
49
|
|
50
50
|
def new
|
@@ -75,7 +75,7 @@
|
|
75
75
|
```
|
76
76
|
|
77
77
|
```view
|
78
|
-
#
|
78
|
+
#groups/new.html.erbのview
|
79
79
|
|
80
80
|
<div class='chat-room-form'>
|
81
81
|
<h1>新規グループ作成</h1>
|
@@ -146,17 +146,16 @@
|
|
146
146
|
### その他の関連するコード
|
147
147
|
|
148
148
|
```model
|
149
|
-
#
|
149
|
+
#Groupモデル
|
150
150
|
|
151
151
|
class Group < ApplicationRecord
|
152
152
|
extend ActiveHash::Associations::ActiveRecordExtensions
|
153
153
|
|
154
|
-
|
154
|
+
has_one :category
|
155
|
-
|
155
|
+
has_one :genre
|
156
156
|
|
157
157
|
has_many :group_users
|
158
158
|
has_many :users, through: :group_users, dependent: :destroy
|
159
|
-
# accepts_nested_attributes_for :group_users
|
160
159
|
has_many :messages, dependent: :destroy
|
161
160
|
|
162
161
|
has_one_attached :image
|
@@ -177,7 +176,7 @@
|
|
177
176
|
```
|
178
177
|
|
179
178
|
```model
|
180
|
-
#
|
179
|
+
#Userモデル
|
181
180
|
|
182
181
|
class User < ApplicationRecord
|
183
182
|
# Include default devise modules. Others available are:
|
@@ -211,7 +210,7 @@
|
|
211
210
|
```
|
212
211
|
|
213
212
|
```model
|
214
|
-
#
|
213
|
+
#GroupUserモデル
|
215
214
|
|
216
215
|
class GroupUser < ApplicationRecord
|
217
216
|
belongs_to :group
|
@@ -220,7 +219,7 @@
|
|
220
219
|
```
|
221
220
|
|
222
221
|
```migration
|
223
|
-
#GroupUsers
|
222
|
+
#GroupUsersのマイグレーションファイル
|
224
223
|
|
225
224
|
class CreateGroupUsers < ActiveRecord::Migration[6.0]
|
226
225
|
def change
|
@@ -234,7 +233,7 @@
|
|
234
233
|
```
|
235
234
|
|
236
235
|
```migration
|
237
|
-
#Group
|
236
|
+
#Groupのマイグレーションファイル
|
238
237
|
|
239
238
|
class CreateGroups < ActiveRecord::Migration[6.0]
|
240
239
|
def change
|
@@ -243,6 +242,7 @@
|
|
243
242
|
t.text :text, null: false
|
244
243
|
t.integer :category_id, null: false
|
245
244
|
t.integer :genre_id, null: false
|
245
|
+
t.references :user, foreign_key: true
|
246
246
|
t.timestamps
|
247
247
|
end
|
248
248
|
end
|
@@ -251,7 +251,7 @@
|
|
251
251
|
```
|
252
252
|
|
253
253
|
```migration
|
254
|
-
#userの関係のある部分
|
254
|
+
#userの関係のある部分のマイグレーションファイル
|
255
255
|
|
256
256
|
create_table :users do |t|
|
257
257
|
## Database authenticatable
|