레일 어레이를 순환 시키려고 할 때 배열이 이미 정의 된 경우에도 여전히 nil을 갖습니다.루프가 항상 레일 4에 nil이 존재하지 않습니다.
코드 :
def gen_address
current_user.accounts.each do |account|
abort(@account.inspect)
next if not account.currency_obj.coin?
if account.payment_addresses.blank?
account.payment_addresses.create(currency: account.currency)
else
address = account.payment_addresses.last
address.gen_address if address.address.blank?
end
end
render nothing: true
end
current_user.accounts 세 항목 배열을 갖는다. 중단은 테스트 용입니다.
current_user.accounts가 있습니다
#<ActiveRecord::Associations::CollectionProxy [#<Account id: 14, member_id: 3, currency: nil, balance: 0.0, locked: 0.0, created_at: "2017-05-23 08:50:11", updated_at: "2017-05-23 08:50:16", in: nil, out: nil, default_withdraw_fund_source_id: nil>, #<Account id: 5, member_id: 3, currency: "btc", balance: 0.0, locked: 0.0, created_at: "2017-05-03 08:37:19", updated_at: "2017-05-03 08:37:19", in: nil, out: nil, default_withdraw_fund_source_id: nil>, #<Account id: 6, member_id: 3, currency: "ltc", balance: 0.0, locked: 0.0, created_at: "2017-05-03 08:37:19", updated_at: "2017-05-03 08:37:19", in: nil, out: nil, default_withdraw_fund_source_id: nil>, #<Account id: 13, member_id: 3, currency: "eth", balance: 0.0, locked: 0.0, created_at: "2017-05-23 08:42:29", updated_at: "2017-05-23 08:42:35", in: nil, out: nil, default_withdraw_fund_source_id: nil>]>
계정이 전무
currency_obj 항상이다 :
module HashCurrencible
extend ActiveSupport::Concern
included do
def currency_obj
Currency.find_by_code(attributes[:currency])
end
end
end
내가 account.currency_obj.coin하지 않을 경우 다음 행에 대해이 오류가
? 제거를 중단 할 때 :undefined method `coin?' for nil:NilClass
사용자 및 계정 모델과 오류를 게시 할 수 있습니까? 어디로 날아가는거야? –
물론, – Maximi
이'current_user.accounts [0]'또는'@ account' nil이라는 질문을 업데이트 했습니까? – AlexN