gpt4 book ai didi

ruby-on-rails - Ruby On Rails迭代器.each block 错误

转载 作者:行者123 更新时间:2023-12-03 08:30:35 24 4
gpt4 key购买 nike

我有此代码捕获的异常,我无法查明错误。

  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:语法错误,意外的$ end,期望keyword_end

如果我删除每个块,一切都很好,那么我想我在该块上犯了一个错误,但是是什么错误?

最佳答案

Ruby不知道++,写+= 1

当您编写index++时,它会认为第一个+是加法,而第二个+是一元符号。后面没有东西就不能有一个标志,因此它需要一个表达式,但是会找到end

关于ruby-on-rails - Ruby On Rails迭代器.each block 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17611261/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com