aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/persistence.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2010-08-02 16:16:02 +0200
committerJosé Valim <jose.valim@gmail.com>2010-08-02 16:16:46 +0200
commitb613c3cc7b08b00595e33d1b5302cd5d42687d4e (patch)
treecda1281eb979fc0a81407a384c71c6da58291dce /activerecord/lib/active_record/persistence.rb
parent311ea94f73c95be87f9a474da122719eebee3f98 (diff)
downloadrails-b613c3cc7b08b00595e33d1b5302cd5d42687d4e.tar.gz
rails-b613c3cc7b08b00595e33d1b5302cd5d42687d4e.tar.bz2
rails-b613c3cc7b08b00595e33d1b5302cd5d42687d4e.zip
Add an internal (private API) after_touch callback. [#5271 state:resolved]
Diffstat (limited to 'activerecord/lib/active_record/persistence.rb')
-rw-r--r--activerecord/lib/active_record/persistence.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb
index 38b91652ee..cbc2220e96 100644
--- a/activerecord/lib/active_record/persistence.rb
+++ b/activerecord/lib/active_record/persistence.rb
@@ -218,6 +218,19 @@ module ActiveRecord
self
end
+ # Saves the record with the updated_at/on attributes set to the current time.
+ # Please note that no validation is performed and no callbacks are executed.
+ # If an attribute name is passed, that attribute is updated along with
+ # updated_at/on attributes.
+ #
+ # Examples:
+ #
+ # product.touch # updates updated_at/on
+ # product.touch(:designed_at) # updates the designed_at attribute and updated_at/on
+ def touch(attribute = nil)
+ update_attribute(attribute, current_time_from_proper_timezone)
+ end
+
private
def create_or_update
raise ReadOnlyRecord if readonly?