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.. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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 > ...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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---