質問編集履歴
7
文法の訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -292,6 +292,22 @@
|
|
292
292
|
|
293
293
|
```
|
294
294
|
|
295
|
+
###group_user#model
|
296
|
+
|
297
|
+
```
|
298
|
+
|
299
|
+
class GroupUser < ApplicationRecord
|
300
|
+
|
301
|
+
belongs_to :group
|
302
|
+
|
303
|
+
belongs_to :user
|
304
|
+
|
305
|
+
end
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
```
|
310
|
+
|
295
311
|
|
296
312
|
|
297
313
|
###calendar#model
|
6
文法の訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -474,7 +474,7 @@
|
|
474
474
|
|
475
475
|
|
476
476
|
|
477
|
-
###calendar#m
|
477
|
+
###calendar#migrate
|
478
478
|
|
479
479
|
```
|
480
480
|
|
5
文法の訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -268,7 +268,239 @@
|
|
268
268
|
|
269
269
|
```
|
270
270
|
|
271
|
-
|
271
|
+
###group#model
|
272
|
+
|
273
|
+
```
|
274
|
+
|
275
|
+
class Group < ApplicationRecord
|
276
|
+
|
277
|
+
has_many :group_users
|
278
|
+
|
279
|
+
has_many :users, through: :group_users
|
280
|
+
|
281
|
+
has_many :calendars
|
282
|
+
|
283
|
+
has_many :messages
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
validates :name, presence: true, uniqueness: true
|
288
|
+
|
289
|
+
end
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
```
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
###calendar#model
|
298
|
+
|
299
|
+
```
|
300
|
+
|
301
|
+
class Calendar < ApplicationRecord
|
302
|
+
|
303
|
+
belongs_to :user
|
304
|
+
|
305
|
+
belongs_to :group
|
306
|
+
|
307
|
+
has_many :messages
|
308
|
+
|
309
|
+
|
310
|
+
|
311
|
+
validates :date, presence: true
|
312
|
+
|
313
|
+
end
|
314
|
+
|
315
|
+
|
316
|
+
|
317
|
+
```
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
###user#model
|
322
|
+
|
323
|
+
```
|
324
|
+
|
325
|
+
class User < ApplicationRecord
|
326
|
+
|
327
|
+
# Include default devise modules. Others available are:
|
328
|
+
|
329
|
+
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
|
330
|
+
|
331
|
+
devise :database_authenticatable, :registerable,
|
332
|
+
|
333
|
+
:recoverable, :rememberable, :validatable
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
has_many :group_users
|
338
|
+
|
339
|
+
has_many :groups, through: :group_users
|
340
|
+
|
341
|
+
has_many :messages
|
342
|
+
|
343
|
+
has_many :calendars
|
344
|
+
|
345
|
+
end
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
```
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
###group#migate
|
354
|
+
|
355
|
+
```
|
356
|
+
|
357
|
+
class CreateGroups < ActiveRecord::Migration[6.0]
|
358
|
+
|
359
|
+
def change
|
360
|
+
|
361
|
+
create_table :groups do |t|
|
362
|
+
|
363
|
+
t.string :name, null: false
|
364
|
+
|
365
|
+
t.index :name, unique: true
|
366
|
+
|
367
|
+
t.timestamps
|
368
|
+
|
369
|
+
end
|
370
|
+
|
371
|
+
end
|
372
|
+
|
373
|
+
end
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
```
|
378
|
+
|
379
|
+
|
380
|
+
|
381
|
+
###user#migrate
|
382
|
+
|
383
|
+
```
|
384
|
+
|
385
|
+
class DeviseCreateUsers < ActiveRecord::Migration[6.0]
|
386
|
+
|
387
|
+
def change
|
388
|
+
|
389
|
+
create_table :users do |t|
|
390
|
+
|
391
|
+
## Database authenticatable
|
392
|
+
|
393
|
+
t.string :name, null: false
|
394
|
+
|
395
|
+
t.string :email, null: false, default: ""
|
396
|
+
|
397
|
+
t.string :encrypted_password, null: false, default: ""
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
## Recoverable
|
402
|
+
|
403
|
+
t.string :reset_password_token
|
404
|
+
|
405
|
+
t.datetime :reset_password_sent_at
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
## Rememberable
|
410
|
+
|
411
|
+
t.datetime :remember_created_at
|
412
|
+
|
413
|
+
|
414
|
+
|
415
|
+
## Trackable
|
416
|
+
|
417
|
+
# t.integer :sign_in_count, default: 0, null: false
|
418
|
+
|
419
|
+
# t.datetime :current_sign_in_at
|
420
|
+
|
421
|
+
# t.datetime :last_sign_in_at
|
422
|
+
|
423
|
+
# t.string :current_sign_in_ip
|
424
|
+
|
425
|
+
# t.string :last_sign_in_ip
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
## Confirmable
|
430
|
+
|
431
|
+
# t.string :confirmation_token
|
432
|
+
|
433
|
+
# t.datetime :confirmed_at
|
434
|
+
|
435
|
+
# t.datetime :confirmation_sent_at
|
436
|
+
|
437
|
+
# t.string :unconfirmed_email # Only if using reconfirmable
|
438
|
+
|
439
|
+
|
440
|
+
|
441
|
+
## Lockable
|
442
|
+
|
443
|
+
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
|
444
|
+
|
445
|
+
# t.string :unlock_token # Only if unlock strategy is :email or :both
|
446
|
+
|
447
|
+
# t.datetime :locked_at
|
448
|
+
|
449
|
+
|
450
|
+
|
451
|
+
|
452
|
+
|
453
|
+
t.timestamps null: false
|
454
|
+
|
455
|
+
end
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
add_index :users, :name, unique: true
|
460
|
+
|
461
|
+
add_index :users, :email, unique: true
|
462
|
+
|
463
|
+
add_index :users, :reset_password_token, unique: true
|
464
|
+
|
465
|
+
# add_index :users, :confirmation_token, unique: true
|
466
|
+
|
467
|
+
# add_index :users, :unlock_token, unique: true
|
468
|
+
|
469
|
+
end
|
470
|
+
|
471
|
+
end
|
472
|
+
|
473
|
+
```
|
474
|
+
|
475
|
+
|
476
|
+
|
477
|
+
###calendar#model
|
478
|
+
|
479
|
+
```
|
480
|
+
|
481
|
+
class CreateCalendars < ActiveRecord::Migration[6.0]
|
482
|
+
|
483
|
+
def change
|
484
|
+
|
485
|
+
create_table :calendars do |t|
|
486
|
+
|
487
|
+
t.string :date
|
488
|
+
|
489
|
+
t.references :group, foreign_key: true
|
490
|
+
|
491
|
+
t.references :user, foreign_key: true
|
492
|
+
|
493
|
+
t.timestamps
|
494
|
+
|
495
|
+
end
|
496
|
+
|
497
|
+
end
|
498
|
+
|
499
|
+
end
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
```
|
272
504
|
|
273
505
|
###補足
|
274
506
|
|
4
文法の訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -206,6 +206,70 @@
|
|
206
206
|
|
207
207
|
|
208
208
|
|
209
|
+
###message#model
|
210
|
+
|
211
|
+
```
|
212
|
+
|
213
|
+
class Message < ApplicationRecord
|
214
|
+
|
215
|
+
belongs_to :user
|
216
|
+
|
217
|
+
belongs_to :group
|
218
|
+
|
219
|
+
belongs_to :calendar
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
validates :content, presence: true, unless: :image?
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
mount_uploader :image, ImageUploader
|
228
|
+
|
229
|
+
end
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
```
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
###message#migrate
|
238
|
+
|
239
|
+
```
|
240
|
+
|
241
|
+
class CreateMessages < ActiveRecord::Migration[6.0]
|
242
|
+
|
243
|
+
def change
|
244
|
+
|
245
|
+
create_table :messages, id: :integer do |t|
|
246
|
+
|
247
|
+
t.string :content
|
248
|
+
|
249
|
+
t.string :image
|
250
|
+
|
251
|
+
t.integer :group_id, foreign_key: true
|
252
|
+
|
253
|
+
t.integer :calendar_id, foreign_key: true
|
254
|
+
|
255
|
+
t.integer :user_id, foreign_key: true
|
256
|
+
|
257
|
+
t.timestamps
|
258
|
+
|
259
|
+
end
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
end
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
```
|
270
|
+
|
271
|
+
|
272
|
+
|
209
273
|
###補足
|
210
274
|
|
211
275
|
何かお気付きの箇所などありましたらご助言いただけると助かります。他のデータも必要でしたら載せますのでおっしゃってください。
|
3
文法の訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,8 +26,6 @@
|
|
26
26
|
|
27
27
|
@message = Message.new
|
28
28
|
|
29
|
-
@messages = @calendar
|
30
|
-
|
31
29
|
@messages = @calendar.messages.includes(:user)
|
32
30
|
|
33
31
|
@calendars = @group
|
2
文法の追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
###解決したいこと
|
2
2
|
|
3
|
-
メッセージを投稿したいのですが、elseの方が読み込まれてしまい、ifの方に
|
3
|
+
メッセージを投稿したいのですが、エラーは出ずにelseの方が読み込まれてしまい、ifの方に読み込まれないです。
|
4
4
|
|
5
5
|
group,calendar,messageとゆう順番にrouteはネストされています。
|
6
6
|
|
7
|
+
calendarのindexでの下のeach文で@calendarsに@groupの値を入れないと表示がされなく、そのため、messagecontrollerで@calendars = @groupとしているのですが、これのせいでcreateでの@messageのあとの@calendarが@groupのidになっているのでしょうか?
|
8
|
+
|
7
|
-
私なりにいろいろ試してみたのですがelseの方が読み込まれるか、No methodとで
|
9
|
+
私なりにいろいろ試してみたのですがelseの方が読み込まれるか、エラーが出てNo methodとでるので全然解決しないのでよければ教えていただきたいです!
|
8
10
|
|
9
11
|
|
10
12
|
|
@@ -90,6 +92,120 @@
|
|
90
92
|
|
91
93
|
```
|
92
94
|
|
95
|
+
### messageのリンクにとぶためのcalendar#index
|
96
|
+
|
97
|
+
```
|
98
|
+
|
99
|
+
.wrapper
|
100
|
+
|
101
|
+
.hoom
|
102
|
+
|
103
|
+
.center
|
104
|
+
|
105
|
+
.center__top
|
106
|
+
|
107
|
+
%h2.center__top__name
|
108
|
+
|
109
|
+
= current_user.name
|
110
|
+
|
111
|
+
.center__naka
|
112
|
+
|
113
|
+
%h5.center__naka__date
|
114
|
+
|
115
|
+
Schedule
|
116
|
+
|
117
|
+
.center__naka__new
|
118
|
+
|
119
|
+
= link_to new_group_calendar_path do
|
120
|
+
|
121
|
+
= icon('fas', 'calendar-plus', class:'new')
|
122
|
+
|
123
|
+
.center__bottom
|
124
|
+
|
125
|
+
- @calendars.calendars.each do |calendar|
|
126
|
+
|
127
|
+
.center__bottom__list
|
128
|
+
|
129
|
+
= link_to group_calendar_messages_path(calendar.group, calendar), class:"a" do
|
130
|
+
|
131
|
+
.center__bottom__list__name
|
132
|
+
|
133
|
+
= calendar.date
|
134
|
+
|
135
|
+
```
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
###message#index
|
140
|
+
|
141
|
+
```
|
142
|
+
|
143
|
+
.hoom
|
144
|
+
|
145
|
+
.light
|
146
|
+
|
147
|
+
.main
|
148
|
+
|
149
|
+
.main__footer
|
150
|
+
|
151
|
+
= form_with model: [@group, @calendar, @message], html: {class: "form"}, local: true do |f|
|
152
|
+
|
153
|
+
.input-box
|
154
|
+
|
155
|
+
= f.text_field :content, class: 'input-box__text', placeholder: 'message'
|
156
|
+
|
157
|
+
= f.label :image, class: 'input-box__image' do
|
158
|
+
|
159
|
+
= icon('fas', 'camera', class: 'input-box__icon')
|
160
|
+
|
161
|
+
= f.file_field :image, class: 'input-box__image__file'
|
162
|
+
|
163
|
+
= f.submit 'Go', class: 'submit__btn'
|
164
|
+
|
165
|
+
.main__header
|
166
|
+
|
167
|
+
%h4.main__header__group
|
168
|
+
|
169
|
+
= @group.name
|
170
|
+
|
171
|
+
.main__header__edit
|
172
|
+
|
173
|
+
= link_to edit_group_path(@group) do
|
174
|
+
|
175
|
+
= icon('fas', 'cog', class:'edit')
|
176
|
+
|
177
|
+
.main__calendar
|
178
|
+
|
179
|
+
.main__calendar__content
|
180
|
+
|
181
|
+
= render @messages
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
```
|
186
|
+
|
187
|
+
###message#indexのrenderの先のリンク
|
188
|
+
|
189
|
+
```
|
190
|
+
|
191
|
+
.box
|
192
|
+
|
193
|
+
.box__username
|
194
|
+
|
195
|
+
= message.user.name
|
196
|
+
|
197
|
+
.box__message
|
198
|
+
|
199
|
+
- if message.content.present?
|
200
|
+
|
201
|
+
%p.box__message__content
|
202
|
+
|
203
|
+
= message.content
|
204
|
+
|
205
|
+
= image_tag message.image.url, class: 'box__message__image' if message.image.present?
|
206
|
+
|
207
|
+
```
|
208
|
+
|
93
209
|
|
94
210
|
|
95
211
|
###補足
|
1
文法の訂正
test
CHANGED
File without changes
|
test
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
|
9
9
|
|
10
10
|
|
11
|
-
###
|
11
|
+
###Messagescontroller
|
12
12
|
|
13
13
|
```
|
14
14
|
|