Controller logic not working


#1

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
…do stuff
end

end

Is this valid?


#2

Hello–

On Nov 29, 2008, at 1:30 PM, Joe S. 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|
unless item.quantity.zero?
# do stuff…
end
end