jeudi 26 janvier 2017

Update database column in rails

I have a problem, I want to update my database's "active" column. my schema =

 tablename(name:string , id:int , active:0 ,created_at)

I want to update active attribute in my rails app after a certain period of time let say 2 days from the created_at time

I have tried few stuff like this from controller but none of this worked for me.. can anyone help ?

def check_aim
@aim = Aim.find(1)

aimdays = @aim.day
futuredate = @aim.created_at+aimdays.days
 if(Time.now == futuredate)
 @aim.active = 0;  // i have tried @aim.update_attribute(:active,1) also didn't word either
 @aim.save
end
 if @aim.save
saved
else
not saved  
end
end
helper_method :check_aim

view class

=debug check_aim

this returns

saved

but when i see my database nothing has changed ... plz help

Aucun commentaire:

Enregistrer un commentaire