我有另一个错误NoMethodError
:
未定义的方法<<'为零:NilClass来自 应用/业务/ bank_accounts / validate_new_transaction.rb:31:在 validate_existence_of_account'!
def validate_existence_of_account!
if @bank_account.blank?
@errors << "Account not found"
end
end
答案 0 :(得分:3)
您的变量@errors
为nil
,您需要将其设置为Array
(我认为这是您想要的),然后再调用<<
:< / p>
@errors = []
@errors << "foobar"
<强>更新强>
您的initialize
方法中存在拼写错误,请使用@errors
代替@erros
。