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

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.

Try this:

item = Item.where(:id => item_id).first

I am actually surprised that it didn't fail earlier.

Need Your Help

Running both PHP and Node.js on Nginx(php extension file for PHP, html extension for node)

javascript php html node.js nginx

Good day, i want handle php file and html on same server, i want that html files handle node on port 8080, and php files handle php5 service. I wrote nginx config like this:

How no make a button show UINavigationBar only in 3 of 5 tabs in UITabBar?

iphone objective-c uinavigationbar

I have an app, where there's a UITabBar with 5 tabs. When user shakes the device, I want the UINavigationBar to push an UIImageView. When I show the UIImageView, I need to hide both tab and nav bars.