[英]Ruby On Rails iterator .each block error
i have an exception caught with this code and i can't pinpoint the error. 我有此代码捕获的异常,我无法查明错误。
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
the error is home_controller.rb:109 syntax error, unexpected keyword_end home_controller.rb:125: syntax error, unexpected $end, expecting keyword_end 错误是home_controller.rb:109语法错误,意外的keyword_end home_controller.rb:125:语法错误,意外$ end,期望的keyword_end
If i remove the each block everithing is fine, so i guess i made a mistake with the block but what mistake ?????? 如果我删除每个块,一切都很好,那么我想我在该块上犯了一个错误,但是是什么错误?
Ruby does not know ++
, write += 1
. Ruby不知道++
,写+= 1
。
When you write index++
, it thinks the first +
is addition, and the second +
a unary sign. 当您编写index++
,它会认为第一个+
是加号,第二个+
是一元符号。 You can't have a sign without something after it, so it expects an expression, but finds end
. 后面没有东西就不能有一个标志,因此它需要一个表达式,但是会找到end
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.