jeudi 22 octobre 2015

Attribute not updating on update_attribute even after reload

I'm doing the rails tutorial on :

http://ift.tt/1EjNCw0

I have this piece of code that is supossed to create a reset_token and save its hash and the time it was created to the database.

def create_reset_digest
    self.reset_token = User.new_token
    update_attribute(:reset_digest,  User.digest(reset_token))
    value = update_attribute(:reset_sent_at, Time.zone.now)
    print value
end

Starting debug before update_attribute on reset_sent_at:

self.reset_sent_at == 2000-01-01 12:36:53 UTC

After it:

self.reset_sent_at == Thu, 22 Oct 2015 12:52:47 UTC +00:00

But doing self.reload makes:

self.reset_sent_at == 2000-01-01 12:36:53 UTC

So maybe update_attribute is not saving on the db?

But print value returns True, indicating a successful save.

I'm not sure what is going on.

Aucun commentaire:

Enregistrer un commentaire