Iterating variables inside a block

I am currently using the ActiveMerchant plugin to create a Paypal
order, but that is not where my problem is.

I am trying to iterate over a variable inside a block, this is what i
got;

Creating item_x in order to display each items in the Paypal

checkout
i = 1
for order_item in @order.order_items do
service.item_name_i = order_item.product.name
#service.item_quantity_i = order_item.quantity
service.amount_i = order_item.price
i+1
end

This is the effect i want to have;

service.item_name_1 = Name of item 1 in the block
service.item_quantity_1 = Quantity of item 1
service.amount_1 = Price of item 1

service.item_name_2 = Name of item 2 in the block

I hope i am making myself understandable, i would really appreciate
some help. I am sure this could easily be done, but i cant figure it
out…

service.item_name_i = order_item.product.name

service.item_name_2 = Name of item 2 in the block

Where does the initial “service” get defined? Unless you’ve got some
magic going on there that lets you dynamically add those instance
variables (or methods if that’s what they are) the above isn’t going to
work even if you were getting ‘i’ to be interpreted correctly.

What’s your end goal?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs