Update a classes attribute from within a controller
So I have an array of items, which I am iterating through and grabbing each item individually. I would like to update the values of a few of the items attributes. I have attempted this like so:
if @request.status = 'Approved' session[:item_ids].each do |item_id| item = Item.where(:id => item_id) item.checked_out = item.requested item.quantity = item.quantity - item.checked_out item.requested = 1 end
This doesn't work unfortunately and has been throwing the error:
undefined method `requested' for #<ActiveRecord::Relation:0x007fd01e6ae2a8>
requested is most definitely an attribute of the item class, so I have no idea why I can't update these values. Any help would be much appreciated!
where returns a collection-like relation object, not Item object.
item = Item.where(:id => item_id).first
I am actually surprised that it didn't fail earlier.