Skip to content

Instantly share code, notes, and snippets.

@tedgrubb
Created July 3, 2013 00:27
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 tedgrubb/5914487 to your computer and use it in GitHub Desktop.
Save tedgrubb/5914487 to your computer and use it in GitHub Desktop.
class ActiveResource::Base
attr_accessor :dirty_attributes
def update_attribute(name, value)
dirty_attributes ||= []
dirty_attributes << name.to_sym
super(*args)
end
def update
run_callbacks :update do
patch_data = {}
dirty_attributes.each do |dirty_attr|
patch_data[dirty_attr] = self.attributes[dirty_attr.to_s]
end
encoded_patch_data = patch_data.send("to_#{self.class.format.extension}")
connection.patch(element_path(prefix_options), encoded_patch_data, self.class.headers).tap do |response|
dirty_attributes = nil
load_attributes_from_response(response)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment