Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
499 views
in Technique[技术] by (71.8m points)

timestamp - "Touch" updated_at column in Rails 2.3.2

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 changes to the attributes and so the updated_at column never changes (even though save is called).

I'd prefer not to disable partial updates (in general, they're useful). I'm guessing that my two options are to:

  1. Add a separate timestamp column to the model (i.e., 'processed_at') and manage this myself, although this seems a bit wasteful/redundant.
  2. Or somehow override the management of the updated_at attribute?

I've heard that Rails 3 will have a 'touch' method which would be exactly what I'm looking for.

Any ideas/options/opinions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...