Ruby On Rails Returning Array NoMethodError

We’ve been continuously working on this issue for a few months and not getting far with it. Since this was first asked, we changed the code (based on what the original developer for the site suggested), but we are still not getting where we need to be.

I’m relatively new to Ruby and am currently taking some courses to learn more about it, so please bear with me. We’re using Ruby 1.9 and Rails 3.2 We use AS 400/DB2 for our database.

We have an online ordering site that you have to have an account set up to access. Depending on what type of account you are set up as, you might have to have your order approved by someone. I.e. if I am a drop ship account, my distributor has to approve what I’m ordering. Also if I am a dedicated drop ship account, my distributor has to approve what I’m ordering as well.

UPDATED 07/07/14

initially, For accounts with 1-2 email addresses everything works great, however in instances where there are more that two we get a NoMethodError:

NoMethodError (undefined method `prfdstw1' for nil:NilClass): 
app/models/order.rb:355:in `submit_order'

We have now been testing with different accounts for several hours and now there does not appear to be a definite pattern to the accounts the fail vs succeed, about 50% of the tests are working regardless of number of emails or type of account.

the lines in question are:

            if sign_on.acctypw1.strip == "DS" or sign_on.acctypw1.strip == "DSD"        
                rec = SignOn.first(:conditions => {:userw1 => login}, :select=> "prfdstw1") 
                webid = rec.prfdstw1 if rec
                def ignore_exception
                   rescue Exception


target_email = Contact.connection.select_values


if sign_on.acctypw1.strip == "DS" or sign_on.acctypw1.strip == "DSD" 
                # If there is no distributor email address, the mailer model will
 substitute in the admin's email from their settings
                 target_email.each do | email_address | 
Mailer.deliver_order_distributor_approval_email(email_address, 'Coastal Pet Online 
Ordering<>', "Order Confirmation Approval", email_details)

Is there a better way to return the array that would allow for more than 2 emails? I am now unsure of the target_email line. we are getting some accounts with no email addresses that are still working, thee doesn’t seem to be any rhyme or reason to this at all.

Thanks in advance for any help!

Ruby is the best programming language in the world - Ruby on Rails.