0

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

If i remove the each block everithing is fine, so i guess i made a mistake with the block but what mistake ??????

1 Answer 1

1

Ruby does not know ++, write += 1.

When you write index++, it thinks the first + is addition, and the second + a unary sign. You can't have a sign without something after it, so it expects an expression, but finds end.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks so much for the solution and explanation. i was going crazy about that. i knew it was something stupidly simple, i'm pretty sure now that i will never do that ++ mistake again thanks to your explanation

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.