質問編集履歴
2
イベントモデル、タグモデル追記しました
test
CHANGED
File without changes
|
test
CHANGED
@@ -514,6 +514,68 @@
|
|
514
514
|
|
515
515
|
</div>
|
516
516
|
|
517
|
+
```イベントモデル
|
518
|
+
|
519
|
+
```イベントモデル
|
520
|
+
|
521
|
+
```ここに言語を入力
|
522
|
+
|
523
|
+
class Event < ApplicationRecord
|
524
|
+
|
525
|
+
extend ActiveHash::Associations::ActiveRecordExtensions
|
526
|
+
|
527
|
+
belongs_to :user
|
528
|
+
|
529
|
+
has_many_attached :images
|
530
|
+
|
531
|
+
belongs_to :facility
|
532
|
+
|
533
|
+
belongs_to :scale
|
534
|
+
|
535
|
+
belongs_to :category
|
536
|
+
|
537
|
+
has_many :event_tag_relations, dependent: :destroy
|
538
|
+
|
539
|
+
has_many :tags, through: :event_tag_relations, dependent: :destroy
|
540
|
+
|
541
|
+
has_many :comments, dependent: :destroy
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
def self.search(search)
|
546
|
+
|
547
|
+
if search != ""
|
548
|
+
|
549
|
+
Event.where('name LIKE ? OR volunteer LIKE ?', "%#{search}%", "%#{search}%")
|
550
|
+
|
551
|
+
# Event.where('category_id.name LIKE(?)', "%#{search}%")
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
+
else
|
556
|
+
|
557
|
+
Event.all
|
558
|
+
|
559
|
+
end
|
560
|
+
|
561
|
+
end
|
562
|
+
|
563
|
+
end
|
564
|
+
|
565
|
+
```タグモデル
|
566
|
+
|
567
|
+
```ここに言語を入力
|
568
|
+
|
569
|
+
class Tag < ApplicationRecord
|
570
|
+
|
571
|
+
has_many :event_tag_relations, dependent: :destroy
|
572
|
+
|
573
|
+
has_many :events, through: :event_tag_relations, dependent: :destroy
|
574
|
+
|
575
|
+
|
576
|
+
|
577
|
+
validates :tagname, uniqueness: true
|
578
|
+
|
579
|
+
end
|
580
|
+
|
517
581
|
```
|
518
|
-
|
519
|
-
```
|
1
アドバイスして頂いたことを元に修正してみました
test
CHANGED
File without changes
|
test
CHANGED
@@ -420,6 +420,100 @@
|
|
420
420
|
|
421
421
|
```
|
422
422
|
|
423
|
+
修正(行ったこと)
|
424
|
+
|
425
|
+
イベントコントローラー
|
426
|
+
|
427
|
+
```ここに言語を入力
|
428
|
+
|
429
|
+
def edit
|
430
|
+
|
431
|
+
@event = Event.find(params[:id])
|
432
|
+
|
433
|
+
@tag = @event.tag
|
434
|
+
|
435
|
+
unless @event.user_id == current_user.id
|
436
|
+
|
437
|
+
redirect_to action: :index
|
438
|
+
|
439
|
+
end
|
440
|
+
|
441
|
+
end
|
442
|
+
|
443
|
+
```エラー文
|
444
|
+
|
445
|
+
```ここに言語を入力
|
446
|
+
|
447
|
+
NoMethodError in EventsController#edit
|
448
|
+
|
449
|
+
undefined method `tag' for #<Event:0x00007fd125875930> Did you mean? tags tap
|
450
|
+
|
451
|
+
Extracted source (around line #39):
|
452
|
+
|
453
|
+
|
454
|
+
|
455
|
+
def edit
|
456
|
+
|
457
|
+
@event = Event.find(params[:id])
|
458
|
+
|
459
|
+
@tag = @event.tag
|
460
|
+
|
461
|
+
unless @event.user_id == current_user.id
|
462
|
+
|
463
|
+
redirect_to action: :index
|
464
|
+
|
465
|
+
end
|
466
|
+
|
423
467
|
```
|
424
468
|
|
469
|
+
修正2
|
470
|
+
|
471
|
+
editビュー
|
472
|
+
|
473
|
+
```ここに言語を入力
|
474
|
+
|
475
|
+
<div class="field", id='tag-field'>
|
476
|
+
|
477
|
+
<label class="label">タグ</label>
|
478
|
+
|
479
|
+
<%= @event.tag class:"input-tag" %>
|
480
|
+
|
481
|
+
</div>
|
482
|
+
|
425
483
|
```
|
484
|
+
|
485
|
+
```エラー文
|
486
|
+
|
487
|
+
```ここに言語を入力
|
488
|
+
|
489
|
+
NoMethodError in Events#edit
|
490
|
+
|
491
|
+
Showing /Users/user/projects/asomemo/app/views/events/edit.html.erb where line #26 raised:
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
undefined method `tag' for #<Event:0x00007fd1272c56f0>
|
496
|
+
|
497
|
+
Did you mean? tags
|
498
|
+
|
499
|
+
tap
|
500
|
+
|
501
|
+
Extracted source (around line #26):
|
502
|
+
|
503
|
+
|
504
|
+
|
505
|
+
<div class="field", id='tag-field'>
|
506
|
+
|
507
|
+
<label class="label">タグ</label>
|
508
|
+
|
509
|
+
<%= @event.tag class:"input-tag" %>
|
510
|
+
|
511
|
+
</div>
|
512
|
+
|
513
|
+
<div class="kouho", id="search-result" >
|
514
|
+
|
515
|
+
</div>
|
516
|
+
|
517
|
+
```
|
518
|
+
|
519
|
+
```
|