teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

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

2017/12/04 04:48

投稿

koume
koume

スコア458

title CHANGED
File without changes
body CHANGED
@@ -24,4 +24,42 @@
24
24
  private method `require' called for {:customer_id=>92}:Hash
25
25
  質問が重複してしまっているのですがこのエラーはどういうことを言っているのでしょうか?
26
26
 
27
- どなたか教えていただけないでしょうか?宜しくお願いします。
27
+ どなたか教えていただけないでしょうか?宜しくお願いします。
28
+
29
+ 追記
30
+ このように記述しています。
31
+ ```ここに言語を入力
32
+ class Customer::BankForm
33
+ include ActiveModel::Model
34
+
35
+ attr_accessor :bank
36
+ delegate :persisted?, :valid?, :save, to: :bank
37
+
38
+ def initialize(bank = nil)
39
+ @bank = bank
40
+ @bank ||= Bank.new
41
+ @customer.build_bank unless @bank
42
+ end
43
+
44
+ def assign_attributes(params = {})
45
+ @params = params
46
+ bank.assign_attributes(bank_params)
47
+ end
48
+
49
+ private
50
+ def bank_params
51
+ @params.require(:bank).permit(:customer_id, :bk_name, :office, :account, :acc_name, :acc_name_kana)
52
+ end
53
+ end
54
+ ```
55
+ @paramsの部分をparamsに変えて実行すると下記エラーに変わります。
56
+ ```ここに言語を入力
57
+ NameError (undefined local variable or method `params' for #<Customer::BankForm: 0x007ff8438dc258>
58
+ Did you mean? @params):
59
+
60
+ app/forms/customer/bank_form.rb:20:in `bank_params'
61
+ app/forms/customer/bank_form.rb:15:in `assign_attributes'
62
+ app/controllers/customer/banks_controller.rb:44:in `create'
63
+
64
+ ```
65
+ 何が原因なのかがわからないので教えていただけないでしょうか?