Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

255
Views
Update a column on update of others columns properly

I would like know a properly way to change a column value if others columns change, i know the classic way with one case return self.prices_updated_at = Time.zone.now if currency_changed?

But i dont know how write it more properly than that when i have many cases

return unless currency_changed? || price1_changed? || price2_changed? ||
                  price3_changed? || price4_changed? ||
                  price5_changed? || price6_changed?

    self.prices_updated_at = Time.zone.now
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use changed_attributes

return unless (changed_attributes.keys & %w[currency price1 price2 price3 price4 price5 price6]).any?
self.prices_updated_at = Time.zone.now
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!