2013-07-12 36 views
0

我有一個異常與此代碼捕獲,我無法精確定位錯誤。Ruby On Rails迭代器。每個塊錯誤

def paypal_content 
    payment = {} 
    payment[:intent] = "sale" 
    payment[:payer] = { :payment_method => "paypal" } 
    payment[:redirect_urls] = { :return_url => "http://localhost:3000/payment/execute", :cancel_url => "http://localhost:3000"} 

    items = [] 
    index = 0 
    @cart.items.each do |item| 
     items[index] = {} 
     items[index][:name] = item.title 
     items[index][:sku] = item.artist 
     items[index][:price] = item.price.to_s 
     items[index][:quantity] = "1" 
     items[index][:currency] = "CHF" 
     index++  
    end <--- this is line 109 

    item_list = {} 
    item_list[:items] = items 

    transactions = [] 
    transactions[0] = {} 
    transactions[0][:item_list] = item_list 
    transactions[0][:amount] = { :total => @cart.total_price.to_s, :currency => "CHF"} 
    transactions[0][:description] = "from Larraby Blaine Esquire" 

    payment[:transactions] = transactions 

    return payment 
    end 

錯誤是 home_controller.rb:109語法錯誤,意想不到的keyword_end home_controller.rb:125:語法錯誤,意想不到的$結束,預計keyword_end

如果我刪除了每個塊everithing是罰款,所以我想我犯了一個錯誤的塊,但什麼錯誤??????

回答

1

紅寶石不知道++,請寫+= 1

當你寫index++時,它認爲第一個+是加法,第二個+是一個一元符號。你不能在沒有任何東西之後有一個符號,所以它期望一個表達式,但是找到end

+1

非常感謝您的解答和解答。我爲此瘋狂。我知道這是一件非常簡單的事情,我很確定,現在我再也不會那樣做,因爲你的解釋會再犯那個++錯誤 – Lefty