質問編集履歴

4

誤ったコードを記載し、申し訳ありませんでした。訂正いたしましたので、ご確認頂けますと幸いです。何卒宜しく御願い致します。

2020/02/28 10:22

投稿

raigakun
raigakun

スコア7

test CHANGED
File without changes
test CHANGED
@@ -352,7 +352,9 @@
352
352
 
353
353
 
354
354
 
355
+ ###変更:グループで作成したタスクの表示画面のビュー
356
+
355
- ###タスクの新規作成画面のビュー(個人とグループ)
357
+ 変更前:タスクの新規作成画面のビュー(個人とグループ)
356
358
 
357
359
 
358
360
 
@@ -588,7 +590,7 @@
588
590
 
589
591
  - ozroro 様にご教授頂いた通り、上記task.controller.rb内に対して、Group.find_by(id: params[:group_id])へ変更し、新規作成画面を表示することができました!
590
592
 
591
- - しかし、記「タスクの新規作成画面のビュー(個人とグループ)」(app/views/task/index.html.erb)
593
+ - しかし、記「タスクの新規作成画面のビュー(個人とグループ)」(app/views/task/index.html.erb)
592
594
 
593
595
  の条件分岐では、elseの方にいかず、groupの方を読み込んでしまいます。
594
596
 
@@ -607,3 +609,95 @@
607
609
 
608
610
 
609
611
  仮説も含めてみました。お手数ですが、何卒ご教授の程宜しく御願い致します。
612
+
613
+
614
+
615
+
616
+
617
+
618
+
619
+
620
+
621
+ #追記3
622
+
623
+ ##追記1の上記の「タスクの新規作成画面のビュー(個人とグループ)」は「グループで作成したタスクの表示画面のビュー」でした。申し訳ありませんでした。
624
+
625
+ ###「タスクの新規作成画面のビュー(個人とグループ)」
626
+
627
+ - ifとelseで条件分岐しております。
628
+
629
+
630
+
631
+
632
+
633
+
634
+
635
+
636
+
637
+ ```
638
+
639
+ <% - if @group_id.present?%>
640
+
641
+ <header class="header2">
642
+
643
+ <nav class="nav2">
644
+
645
+ <ul class="header_menu2">
646
+
647
+ <li class="nav-link">
648
+
649
+ <%= @group.name %>
650
+
651
+ </li>
652
+
653
+ <ul class="header_menu2_inner2">
654
+
655
+ <li><%= link_to "Create Group Tasks", new_group_task_path(@group), class: "nav-link listNew2", method: :get %></li>
656
+
657
+ <li><%= link_to "Edit Group",edit_group_path(@group), class: "nav-link listNew3", method: :get %></li>
658
+
659
+ </ul>
660
+
661
+ </ul>
662
+
663
+ </nav>
664
+
665
+ </header>
666
+
667
+ <div class="tasknewPage">
668
+
669
+ <div class="container">
670
+
671
+ <%= form_with model: @task, url: { action: :create }, class: "new_task", local: true do |f| %>
672
+
673
+ <%= f.label :title %>
674
+
675
+ <%= f.text_field :title, autofocus: true, class: "form-control taskName", placeholder: "タスク名" %>
676
+
677
+ <div class="text-center"><%= f.submit "作成", class: "submitBtn" %></div>
678
+
679
+ <% end %>
680
+
681
+
682
+
683
+ <% else %>
684
+
685
+ <%= form_with model: @task, url: { action: :create }, class: "new_task", local: true do |f| %>
686
+
687
+ <%= f.label :title %>
688
+
689
+ <%= f.text_field :title, autofocus: true, class: "form-control taskName", placeholder: "タスク名" %>
690
+
691
+ <div class="text-center"><%= f.submit "作成", class: "submitBtn" %></div>
692
+
693
+ <% end %>
694
+
695
+ <% end %>
696
+
697
+
698
+
699
+
700
+
701
+
702
+
703
+ ```

3

少し文言追加いたしました。何卒宜しく御願い致します。

2020/02/28 10:22

投稿

raigakun
raigakun

スコア7

test CHANGED
File without changes
test CHANGED
@@ -586,7 +586,7 @@
586
586
 
587
587
 
588
588
 
589
- - ご教授頂いた通り、上記task.controller.rb内の記述を変更し、新規作成画面を表示することができました!
589
+ - ozroro 様にご教授頂いた通り、上記task.controller.rb内に対して、Group.find_by(id: params[:group_id])へ変更し、新規作成画面を表示することができました!
590
590
 
591
591
  - しかし、上記「タスクの新規作成画面のビュー(個人とグループ)」(app/views/task/index.html.erb)
592
592
 

2

ご教授いただきありがとうございます。情報を追加いたしました。何卒宜しく御願い致します。

2020/02/28 10:10

投稿

raigakun
raigakun

スコア7

test CHANGED
File without changes
test CHANGED
@@ -565,3 +565,45 @@
565
565
  end
566
566
 
567
567
  ```
568
+
569
+
570
+
571
+
572
+
573
+
574
+
575
+
576
+
577
+ #追記2
578
+
579
+
580
+
581
+ ###タスク作成画面の表示画面
582
+
583
+ ####個人でタスク作成の場合
584
+
585
+ [個人でのタスク作成の現状](https://gyazo.com/1008f7b5b84a7cc49d5b672bed3f1d01)
586
+
587
+
588
+
589
+ - ご教授頂いた通り、上記task.controller.rb内の記述を変更し、新規作成画面を表示することができました!
590
+
591
+ - しかし、上記「タスクの新規作成画面のビュー(個人とグループ)」(app/views/task/index.html.erb)
592
+
593
+ の条件分岐では、elseの方にいかず、groupの方を読み込んでしまいます。
594
+
595
+ - 動画上では、メリーと表示されているheaderはありますが、目標はそのheaderは表示されないこと。
596
+
597
+
598
+
599
+ ###グループでタスク作成の画面
600
+
601
+ [グループでのタスク作成の現状](https://gyazo.com/7e4eb04ba36dd435fe77446875423613)
602
+
603
+
604
+
605
+ - グループではタスクの新規作成、表示はできる。しかし、バイキンマンと表示されているheaderが、タスク新規作成画面になるとメリーになってしまう。(おそらく、DBのgroupテーブルのidの1を読み込んでいる。
606
+
607
+
608
+
609
+ 仮説も含めてみました。お手数ですが、何卒ご教授の程宜しく御願い致します。

1

ご確認ありがとうございます。追記いたしました。宜しく御願い致します。

2020/02/28 10:07

投稿

raigakun
raigakun

スコア7

test CHANGED
File without changes
test CHANGED
@@ -205,3 +205,363 @@
205
205
 
206
206
 
207
207
  以上、お手数ですが、何卒ご教授の程宜しく御願い致します。
208
+
209
+
210
+
211
+
212
+
213
+ #追記
214
+
215
+
216
+
217
+ ####groupsモデルのコード
218
+
219
+
220
+
221
+ ```groub.rb
222
+
223
+ class Group < ApplicationRecord
224
+
225
+ has_many :group_users, dependent: :destroy
226
+
227
+ has_many :users, through: :group_users, dependent: :destroy
228
+
229
+ has_many :tasks, dependent: :destroy
230
+
231
+
232
+
233
+ validates :name, presence: true, uniqueness: true
234
+
235
+ end
236
+
237
+ ```
238
+
239
+
240
+
241
+ ###Taskモデルのコード
242
+
243
+
244
+
245
+ ```task.rb
246
+
247
+ class Task < ApplicationRecord
248
+
249
+ # belongs_to :group
250
+
251
+ belongs_to :user
252
+
253
+ # belongs_to :groups
254
+
255
+ has_many :comments, dependent: :destroy
256
+
257
+
258
+
259
+ # validates :title, length: {in: 1..255}
260
+
261
+ end
262
+
263
+ ```
264
+
265
+
266
+
267
+ ###個人モデルのコード
268
+
269
+
270
+
271
+ ```user.rb
272
+
273
+ class User < ApplicationRecord
274
+
275
+ # Include default devise modules. Others available are:
276
+
277
+ # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
278
+
279
+ #usernameを必須・一意とする
280
+
281
+
282
+
283
+ devise :database_authenticatable, :registerable,
284
+
285
+ :recoverable, :rememberable, :validatable
286
+
287
+
288
+
289
+ has_many :group_users, dependent: :destroy
290
+
291
+ has_many :groups, through: :group_users, dependent: :destroy
292
+
293
+ has_many :tasks, dependent: :destroy
294
+
295
+
296
+
297
+ validates :username, presence: true, length: { maximum: 20 }
298
+
299
+ #usernameを利用してログインするようにオーバーライド
300
+
301
+ def self.find_first_by_auth_conditions(warden_conditions)
302
+
303
+ conditions = warden_conditions.dup
304
+
305
+ if login = conditions.delete(:login)
306
+
307
+ #認証の条件式を変更する
308
+
309
+ where(conditions).where(["username = :value", { :value => username }]).first
310
+
311
+ else
312
+
313
+ where(conditions).first
314
+
315
+ end
316
+
317
+ end
318
+
319
+
320
+
321
+ #emailを不要とする
322
+
323
+ def email_required?
324
+
325
+ false
326
+
327
+ end
328
+
329
+
330
+
331
+ def email_changed?
332
+
333
+ false
334
+
335
+ end
336
+
337
+
338
+
339
+ def will_save_change_to_email?
340
+
341
+ false
342
+
343
+ end
344
+
345
+
346
+
347
+ end
348
+
349
+
350
+
351
+ ```
352
+
353
+
354
+
355
+ ###タスクの新規作成画面のビュー(個人とグループ)
356
+
357
+
358
+
359
+ ```app/views/task/index.html.erb
360
+
361
+ <header class="header2">
362
+
363
+ <nav class="nav2">
364
+
365
+ <ul class="header_menu2">
366
+
367
+ <li class="nav-link">
368
+
369
+ <%= @group.name %>
370
+
371
+ </li>
372
+
373
+ <ul class="header_menu2_inner2">
374
+
375
+ <li><%= link_to "Create Group Tasks", new_group_task_path(@group), class: "nav-link listNew2" %></li>
376
+
377
+ <li><%= link_to "Edit Group",edit_group_path(@group), class: "nav-link listNew3", method: :get %></li>
378
+
379
+ </ul>
380
+
381
+ </ul>
382
+
383
+ </nav>
384
+
385
+ </header>
386
+
387
+
388
+
389
+ <div class="topPage">
390
+
391
+ <div class="taskWrapper">
392
+
393
+ <% @group.tasks.each do |task| %>
394
+
395
+ <div class="task">
396
+
397
+ <div class="task_header">
398
+
399
+ <h2 class="task_header_title"><%= task.title %></h2>
400
+
401
+ <div class="task_header_action">
402
+
403
+ <%= link_to content_tag(:i, '', class: 'fas fa-trash'), task, method: :delete, data: { confirm: "#{task.title}を本当に削除しますか?" } %>
404
+
405
+ <%= link_to(content_tag(:i, '', class: 'fas fa-pen'), edit_task_path(task)) %>
406
+
407
+ </div>
408
+
409
+ </div>
410
+
411
+ <div class="commentWrapper">
412
+
413
+ <% task.comments.each do |comment| %>
414
+
415
+ <%= link_to task_comment_path(task, comment), class:"commentDetail_link" do %>
416
+
417
+ <div class="comment">
418
+
419
+ <h3 class="comment_title"><%= comment.title %></h3>
420
+
421
+ <% if comment.memo.size > 0 %>
422
+
423
+ <div class="comment_detail is-exist"><i class="fas fa-bars"></i></div>
424
+
425
+ <% end %>
426
+
427
+ </div>
428
+
429
+ <% end %>
430
+
431
+ <% end %>
432
+
433
+ <div class="addComment">
434
+
435
+ <i class="far fa-plus-square"></i>
436
+
437
+ <%= link_to "さらにコメントを追加", new_task_comment_path(task), class: "addComment_link" %>
438
+
439
+ </div>
440
+
441
+ </div>
442
+
443
+ </div>
444
+
445
+ <% end %>
446
+
447
+ </div>
448
+
449
+ </div>
450
+
451
+ ```
452
+
453
+
454
+
455
+ ###groups, tasks, 個人テーブルの定義
456
+
457
+
458
+
459
+ ```schema.rb
460
+
461
+ ActiveRecord::Schema.define(version: 2020_02_25_061850) do
462
+
463
+
464
+
465
+ create_table "comments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
466
+
467
+ t.string "title", null: false
468
+
469
+ t.text "memo"
470
+
471
+ t.bigint "task_id", null: false
472
+
473
+ t.datetime "created_at", null: false
474
+
475
+ t.datetime "updated_at", null: false
476
+
477
+ t.index ["task_id"], name: "index_comments_on_task_id"
478
+
479
+ end
480
+
481
+
482
+
483
+ create_table "group_users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
484
+
485
+ t.bigint "group_id"
486
+
487
+ t.bigint "user_id"
488
+
489
+ t.datetime "created_at", null: false
490
+
491
+ t.datetime "updated_at", null: false
492
+
493
+ t.index ["group_id"], name: "index_group_users_on_group_id"
494
+
495
+ t.index ["user_id"], name: "index_group_users_on_user_id"
496
+
497
+ end
498
+
499
+
500
+
501
+ create_table "groups", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
502
+
503
+ t.string "name", null: false
504
+
505
+ t.datetime "created_at", null: false
506
+
507
+ t.datetime "updated_at", null: false
508
+
509
+ t.index ["name"], name: "index_groups_on_name", unique: true
510
+
511
+ end
512
+
513
+
514
+
515
+ create_table "tasks", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
516
+
517
+ t.string "title", null: false
518
+
519
+ t.bigint "user_id", null: false
520
+
521
+ t.bigint "group_id"
522
+
523
+ t.datetime "created_at", null: false
524
+
525
+ t.datetime "updated_at", null: false
526
+
527
+ t.index ["group_id"], name: "index_tasks_on_group_id"
528
+
529
+ t.index ["user_id"], name: "index_tasks_on_user_id"
530
+
531
+ end
532
+
533
+
534
+
535
+ create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
536
+
537
+ t.string "encrypted_password", default: "", null: false
538
+
539
+ t.string "reset_password_token"
540
+
541
+ t.datetime "reset_password_sent_at"
542
+
543
+ t.datetime "remember_created_at"
544
+
545
+ t.datetime "created_at", null: false
546
+
547
+ t.datetime "updated_at", null: false
548
+
549
+ t.string "username", default: "", null: false
550
+
551
+ t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
552
+
553
+ end
554
+
555
+
556
+
557
+ add_foreign_key "group_users", "groups"
558
+
559
+ add_foreign_key "group_users", "users"
560
+
561
+ add_foreign_key "tasks", "groups"
562
+
563
+ add_foreign_key "tasks", "users"
564
+
565
+ end
566
+
567
+ ```