I have an database items and two items in it. They have column named “popularity”, that I set to 0.
class Item < ActiveRecord::Base
attr_accessible .. :popularity, ..
before_create :default_values
def default_values
if self.popularity.nil? == true || self.popularity.blank? == true || self.popularity.class != Integer
self.popularity = 0
end
end
How to change this value via code\console and save it?
I tried
Item.find(1).popularity = 1
Item.save
But it didn’t save my val. Whats wrong?
here is the solution