In Rails’ ActiveRecord, what is touch for?

As per the API Documentation, it is a method that only updates the specified timestamps of the model with the current time. So in order to update the updated_at field:

product.touch

or to update the updated_at and designed_at fields:

product.touch(:designed_at) 

Now, I have never used this method before, but I’d think it would be useful in a situation to “bump” a question (like on Stack Overflow) to the top of a search query without actually changing the contents.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)