Skip to content

Instantly share code, notes, and snippets.

@acrookston
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acrookston/13bd4403d87e7ce336e8 to your computer and use it in GitHub Desktop.
Save acrookston/13bd4403d87e7ce336e8 to your computer and use it in GitHub Desktop.
Rails update_attributes without updating the updated_at field
class Example < ActiveRecord::Base
include WithoutTimestamps
def update_something
update_without_timestamps something: "is changed"
end
def alternatively
self.something = "is changed"
update_without_timestamps
end
end
# models/concerns/without_timestamps.rb
module WithoutTimestamps
def update_without_timestamps(attributes=nil)
class << self
def record_timestamps; false; end
end
self.attributes = attributes if attributes
success = save
class << self
remove_method :record_timestamps
end
success
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment