Help with resource generation

Hey all,

I'm creating a game app and looking to figure out how to go about creating all of the resources I need for a game session the best way.

Where I'm currently stuck is that on creating a new game session, I want several resources to be generated at the same time (largely with pre-fab values stored).

So, when creating a new Game, I want to have:
- 2 players (inheriting from a User class)
- a game board
- a turn

and several other resources I'm sure I can work through (when a player is created, i need to create a 'hand' and a 'principality,' etc... I believe that this will all work similarly as creating the game).

So, I guess I'm curious where that logic should live?
In the Games controller? within its 'create' method include generating the necessary other resources? or somewhere else?

I've currently got it set up so that if there aren't two users with the correct 'game_id', then it directs to a form to create another user... which I don't feel like is ideal, but for right now, I'm just working through MVP. Happily refactor / restructure it further down the line.


*edit: just realized this might also be a good moment for 'after_save' or some such. anyways, any help or advice would be appreciated!

1 thought on “Help with resource generation”

  1. Hey,
    If I were you, I would look into Service Objects. Basically, when you are in the create action in the GamesController, you want to send ur data further to the Service Object that will create all needed resources.


Leave a Comment