vendredi 4 septembre 2015

Ruby on Rails: How to update instance attributes inside the model

Hi I am working on a rails project and I have an scheduler object. I want to set a method inside the instance to automatically update the next_due attribute to be the upcoming due date. All schedules occur daily for simplicity. I have seeded the scheduler so every instance has a next_due value.

Below is my code and it does not seem working.

class ScheduledTask < ActiveRecord::Base
  attr_accessible :next_due

  def self.update_next_due
    while next_due < DateTime.now
      next_due += 1.day
    end
  end  
end

Help is greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire