Forum: Ruby on Rails controller logic not working

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
5ef7330ef2624f4edf4bdc07d84ad8bb?d=identicon&s=25 Joe Smith (apple17)
on 2008-11-29 22:30
So I've written this code in my controller and it doesn't seem to
process my records and I don't know why.

error = nil
@my_cart = @user.shopping_cart
@my_cart_items = @user.shopping_cart.shopping_cart_items
for shopping_cart_item in @my_cart_items
   if @quantity > 0 stuff


Is this valid?
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2008-11-29 22:55
(Received via mailing list)

On Nov 29, 2008, at 1:30 PM, Joe Smith wrote:

>   end
> end
> Is this valid?
> --

No. This doesn't look like it should work. I'd really recommend
reading up on Ruby a bit. @my_cart_items would appear to be a
collection (an array). Using "for" you are iterating over that list
but you are not using the individual item yielded by the iterator. So,
perhaps what you wanted was:

for shopping_cart_item in @my_cart_items do |item|
     # do stuff...
This topic is locked and can not be replied to.