質問編集履歴

1

修正後のエラーを追記しました。

2017/12/04 04:48

投稿

koume
koume

スコア458

test CHANGED
File without changes
test CHANGED
@@ -51,3 +51,79 @@
51
51
 
52
52
 
53
53
  どなたか教えていただけないでしょうか?宜しくお願いします。
54
+
55
+
56
+
57
+ 追記
58
+
59
+ このように記述しています。
60
+
61
+ ```ここに言語を入力
62
+
63
+ class Customer::BankForm
64
+
65
+ include ActiveModel::Model
66
+
67
+
68
+
69
+ attr_accessor :bank
70
+
71
+ delegate :persisted?, :valid?, :save, to: :bank
72
+
73
+
74
+
75
+ def initialize(bank = nil)
76
+
77
+ @bank = bank
78
+
79
+ @bank ||= Bank.new
80
+
81
+ @customer.build_bank unless @bank
82
+
83
+ end
84
+
85
+
86
+
87
+ def assign_attributes(params = {})
88
+
89
+ @params = params
90
+
91
+ bank.assign_attributes(bank_params)
92
+
93
+ end
94
+
95
+
96
+
97
+ private
98
+
99
+ def bank_params
100
+
101
+ @params.require(:bank).permit(:customer_id, :bk_name, :office, :account, :acc_name, :acc_name_kana)
102
+
103
+ end
104
+
105
+ end
106
+
107
+ ```
108
+
109
+ @paramsの部分をparamsに変えて実行すると下記エラーに変わります。
110
+
111
+ ```ここに言語を入力
112
+
113
+ NameError (undefined local variable or method `params' for #<Customer::BankForm: 0x007ff8438dc258>
114
+
115
+ Did you mean? @params):
116
+
117
+
118
+
119
+ app/forms/customer/bank_form.rb:20:in `bank_params'
120
+
121
+ app/forms/customer/bank_form.rb:15:in `assign_attributes'
122
+
123
+ app/controllers/customer/banks_controller.rb:44:in `create'
124
+
125
+
126
+
127
+ ```
128
+
129
+ 何が原因なのかがわからないので教えていただけないでしょうか?