Created
November 17, 2008 10:37
-
-
Save ariejan/25721 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# STI, this is the base model which is stored in the database | |
class Character < ActiveRecord::Base | |
belongs_to :location | |
def move_to(new_location) | |
update_attribute(:location_id, new_location.id) | |
# or: | |
# self.location = new_location | |
# save | |
end | |
end | |
class PlayerCharacter < Character | |
end | |
location_1 = Location.find(1) | |
location_2 = Location.find(2) | |
# Behold the following: | |
@player_character.location => location_1 | |
@player_character.move_to(location_2) => true | |
@player_character.location => location_1 # Even after @player_character.reload | |
# This does work: | |
@player_character.location => location_1 | |
@player_character.location = location_2 | |
@player_character.save | |
@player_character.location => location_2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment