Skip to content

Instantly share code, notes, and snippets.

@MarceloCajueiro
Forked from rodrigoulisses/gist:5094095
Last active December 14, 2015 13:29
Show Gist options
  • Save MarceloCajueiro/5094148 to your computer and use it in GitHub Desktop.
Save MarceloCajueiro/5094148 to your computer and use it in GitHub Desktop.
class PeopleController < CrudController
respond_to :js
def new
object = build_resource
object.personable = Individual.new
super
end
protected
def update_resource(object, resource_params)
object.localized.assign_attributes(*resource_params)
if object.valid? && has_personable_and_it_changed?(object)
personable_was(object).destroy
end
object.save
end
def has_personable_and_it_changed?(object)
object.personable_type_was && object.personable_type_was != object.personable_type
end
def personable_was(object)
object.personable_type.constantize.find(object.personable_id_was)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment