Skip to content

Instantly share code, notes, and snippets.

@acrookston acrookston/example.rb
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.