Ruby On Rails Returning Array NoMethodError

烈酒焚心 提交于 2019-12-13 05:45:53

问题


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
                   begin
                     yield  
                   rescue Exception
                  end
                end   

and

target_email = Contact.connection.select_values
("SELECT EMAL23 FROM WEBOEL23 WHERE ACT223 = #
{Contact.connection.quote(rec.prfdstw1)}").uniq

and

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<noreply@coastalpet.com>', "Order Confirmation Approval", email_details)
                 end

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!

来源:https://stackoverflow.com/questions/24534925/ruby-on-rails-returning-array-nomethoderror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!