“Touch” updated_at column in Rails 2.3.2

前端 未结 2 1131
太阳男子
太阳男子 2020-12-14 07:38

I have a process which iterates through a bunch of ActiveRecord models, does some processing, and saves the models again. Often though, the processing doesn\'t result in an

相关标签:
2条回答
  • 2020-12-14 07:45

    Actually the touch method is already in Rails 2.3.x, so you can simply do:

    model.touch
    

    To update the updated_at column. Alternatively, to update some other column with the current date and time use:

    model.touch(:column_name)
    
    0 讨论(0)
  • 2020-12-14 07:54

    Now that the 2.3.x line has come and gone, a more definitive answer is that touch didn't make it into ActiveRecord until 2.3.8. So, anyone using still using Rails 2.3.2 (as the OP was -- and as I currently am) will need to find another way to "touch" their records.

    0 讨论(0)
提交回复
热议问题