Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class A < ActiveRecord::Base
def update_attributes_changing_type(attrs)
object = if attrs.keys.include?('type') || attrs.keys.include?(:type)
self.becomes((attrs['type'] || attrs[:type]).constantize)
else
self
end
object.class.instance_variable_set('@finder_needs_type_condition', :false)
object.update_attributes(attrs)
object.class.instance_variable_set('@finder_needs_type_condition', nil)
object
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment