-
-
Save MarceloCajueiro/5094148 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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