无法在Ruby中使循环中断正常工作

时间:2012-08-21 12:37:36

标签: ruby-on-rails cycle break

我想在i = 250 I时退出循环,但是我在使用中断逻辑或使用Mass Pay API操作方面遇到了一些麻烦。

以下是我的佣金任务的代码:

     require 'httpclient'
    task :pay => :environment do
    clnt = HTTPClient.new
    i = 249;
    data = {    "METHOD" => "MassPay",
    "VERSION" => "90",
    'USER' => 'payer_1342623102_biz_api1.gmail.com',#'payer_1342623102_biz_api1.gmail.com',
    'PWD' => '1342623141',#'1342623141',
    'SIGNATURE' => 'Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MPnj0SEIENMKd6jvnKL',
    "RECEIVERTYPE" => "EmailAddress",
    "CURRENCYCODE" => "USD"}
    @users = User.all
    @users.each do |user|
        if i==250
            break
        end
        data["L_EMAIL#{i}"] = "#{user.email}"
        data["L_AMT#{i}"] = "1.21"
        i+=1
        puts i
        end
    uri = "https://api-3t.sandbox.paypal.com/nvp"
      res = clnt.post(uri, data)
      puts res.body

但是当我使用此代码时,PayPal会给我错误:

   missing L_AMT parametr

但是这里是来自控制台的代码,它打印我的价值,数据,我发送给PayPal的内容和回复:

    250
   {"METHOD"=>"MassPay", "VERSION"=>"90", "USER"=>"payer_1342623102_biz_api1.gmail.
   com", "PWD"=>"1342623141", "SIGNATURE"=>"Ay2zwWYEoiRoHTTVv365EK8U1lNzAESedJw09MP
   nj0SEIENMKd6jvnKL", "RECEIVERTYPE"=>"EmailAddress", "CURRENCYCODE"=>"USD",    
  "L_EMAIL249"=>"new@mail.com", "L_AMT249"=>"1.21"}
   TIMESTAMP=2012%2d08%2d21T12%3a31%3a06Z&CORRELATIONID=f84d95d199c73&ACK=Failure&V
   ERSION=90&BUILD=3516191&L_ERRORCODE0=81125&L_SHORTMESSAGE0=Missing%20Parameter&L
   _LONGMESSAGE0=L_Amt%20%3a%20Required%20parameter%20missing&L_SEVERITYCODE0=Error

所以认为它是break运算符的东西,因为当我和TWO用户一起运行这个任务时它会重复。

你能说明为什么会这样吗?

0 个答案:

没有答案