Created
August 9, 2012 01:54
-
-
Save Breefield/3300273 to your computer and use it in GitHub Desktop.
Generate Board on Initialize
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 Board < ActiveRecord::Base | |
belongs_to :game | |
# After initialize we generate new tiles and store them in the objects tiles accessor | |
# When this model is retrieved through ActiveRecord the tiles are not generated and we get the | |
# tile set that was saved in the database. | |
after_initialize :place_tiles | |
def place_tiles | |
# The tiles hash is stored in a text field, Rails handles this | |
self.tiles = generate_tiles | |
end | |
... | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment