質問編集履歴
1
質問に対するコードを追記のため修正。
test
CHANGED
File without changes
|
test
CHANGED
@@ -24,8 +24,6 @@
|
|
24
24
|
|
25
25
|
|
26
26
|
|
27
|
-
|
28
|
-
|
29
27
|
# バージョン
|
30
28
|
|
31
29
|
- Rails 6.0.3.4
|
@@ -118,23 +116,7 @@
|
|
118
116
|
|
119
117
|
[Screenshot]: /Users/○/projects/action_app/tmp/screenshots/failures_r_spec_example_groups_nested_nested_2_新規投稿後、保存できず、入力ページにとどまる_387.png
|
120
118
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
# ./app/views/habits/index.html.erb:19:in `block in _app_views_habits_index_html_erb___4534987002136358121_70092370747140'
|
126
|
-
|
127
|
-
# ./app/views/habits/index.html.erb:4:in `_app_views_habits_index_html_erb___4534987002136358121_70092370747140'
|
128
|
-
|
129
|
-
|
119
|
+
(上記と同じエラー 文字数制限に引っかかってしまい省略)
|
130
|
-
|
131
|
-
# --- Caused by: ---
|
132
|
-
|
133
|
-
# NoMethodError:
|
134
|
-
|
135
|
-
# undefined method `if_1' for nil:NilClass
|
136
|
-
|
137
|
-
# ./app/views/habits/index.html.erb:19:in `block in _app_views_habits_index_html_erb___4534987002136358121_70092370747140'
|
138
120
|
|
139
121
|
|
140
122
|
|
@@ -495,3 +477,113 @@
|
|
495
477
|
|
496
478
|
|
497
479
|
どうぞよろしくお願いします。
|
480
|
+
|
481
|
+
|
482
|
+
|
483
|
+
# 追記
|
484
|
+
|
485
|
+
|
486
|
+
|
487
|
+
##### 保存ボタンを押した時のコード(createアクションの動き)
|
488
|
+
|
489
|
+
|
490
|
+
|
491
|
+
```ruby
|
492
|
+
|
493
|
+
class RulesController < ApplicationController
|
494
|
+
|
495
|
+
def index
|
496
|
+
|
497
|
+
@rule = Rule.new
|
498
|
+
|
499
|
+
end
|
500
|
+
|
501
|
+
|
502
|
+
|
503
|
+
def create
|
504
|
+
|
505
|
+
@rule = Rule.new(rule_params)
|
506
|
+
|
507
|
+
if @rule.save
|
508
|
+
|
509
|
+
redirect_to habits_path
|
510
|
+
|
511
|
+
else
|
512
|
+
|
513
|
+
render 'index'
|
514
|
+
|
515
|
+
end
|
516
|
+
|
517
|
+
end
|
518
|
+
|
519
|
+
|
520
|
+
|
521
|
+
private
|
522
|
+
|
523
|
+
|
524
|
+
|
525
|
+
def rule_params
|
526
|
+
|
527
|
+
params.require(:rule).permit(:if_1, :if_2, :if_3, :if_4, :if_5, :then_1, :then_2, :then_3,:then_4, :then_5).merge(user_id: current_user.id)
|
528
|
+
|
529
|
+
end
|
530
|
+
|
531
|
+
end
|
532
|
+
|
533
|
+
```
|
534
|
+
|
535
|
+
|
536
|
+
|
537
|
+
##### spec/support/log_in_support.rbのコード(ユーザーがログインした時の動き)
|
538
|
+
|
539
|
+
```ruby
|
540
|
+
|
541
|
+
module LogInSupport
|
542
|
+
|
543
|
+
# ログインを前提とする結合コードにて使用するため
|
544
|
+
|
545
|
+
def log_in(user)
|
546
|
+
|
547
|
+
visit new_user_session_path
|
548
|
+
|
549
|
+
fill_in 'email', with: user.email
|
550
|
+
|
551
|
+
fill_in 'password', with: user.password
|
552
|
+
|
553
|
+
find('input[name="commit"]').click
|
554
|
+
|
555
|
+
expect(current_path).to eq "/habits.#{user.id}"
|
556
|
+
|
557
|
+
end
|
558
|
+
|
559
|
+
end
|
560
|
+
|
561
|
+
|
562
|
+
|
563
|
+
```
|
564
|
+
|
565
|
+
##### spec/factories/users.rbのコード
|
566
|
+
|
567
|
+
```
|
568
|
+
|
569
|
+
FactoryBot.define do
|
570
|
+
|
571
|
+
factory :user do
|
572
|
+
|
573
|
+
nickname { Faker::Games::Pokemon.name }
|
574
|
+
|
575
|
+
email { Faker::Internet.unique.email }
|
576
|
+
|
577
|
+
# ランダムで生成する際、英数字になるよう'1a'追加
|
578
|
+
|
579
|
+
password { '1a' + Faker::Internet.unique.password(min_length: 15) }
|
580
|
+
|
581
|
+
password_confirmation { password }
|
582
|
+
|
583
|
+
birthdate { Faker::Date.birthday }
|
584
|
+
|
585
|
+
end
|
586
|
+
|
587
|
+
end
|
588
|
+
|
589
|
+
```
|