0

I want to update an specific attribut in my database after save data.

For example i have an column in my table which called pending and it's an boolean. i want to set this value to true when data was saved.

after_save :do_something

private
def do_something
  self.update_column(:pending, true)
end

This doesn't work. Anyone here who has an solution?

pkberlin
  • 812
  • 1
  • 13
  • 31

2 Answers2

0

You can modify your attribute directly like:

after_save { |user| user.username = user.username.downcase }
Sumit Munot
  • 3,748
  • 1
  • 32
  • 51
0

Try after_commit instead of after_save. It will operate outside of the save transaction.

Chris Aitchison
  • 4,656
  • 1
  • 27
  • 43