ruby on rails - " undefined method `[]' for nil:NilClass " -


<%   @loans.each |loan_rec|    loan=loan_rec.info    if loan['_loanname'].blank?     loan_name = 'no loan title'   else     loan_name = loan['_loanname']   end end %> 

i getting error of undefined method `[]' nil:nilclass. undefined? , when print loan array in loop, gives following result:

{   "_lendingcategory"=>"private real estate loan",   "email"=>"entregeorge@gmail.com",   "firstname"=>"testdavid",   "id"=>3573,   "_loanname"=>"null",   "lastname"=>"testgeorge",   "_desiredtermlength"=>"3",   "_transactiontype0"=>"purchase",   "_cashcontribution"=>100000.0,   "_netloanamountrequested0"=>8000000.0 } 

you have @ least 1 loan loan_rec.info nil. can try:

loan = loan_rec.info || loan.new 

as quick fix, should figure figure out how avoid nil in first place.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -