Skip to content

Instantly share code, notes, and snippets.

@Breefield
Created August 9, 2012 01:54
Show Gist options
  • Save Breefield/3300273 to your computer and use it in GitHub Desktop.
Save Breefield/3300273 to your computer and use it in GitHub Desktop.
Generate Board on Initialize
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