Jon Cox wrote:

> I've created the map, game_model and match using scaffold as i want to
> be able to maintain them through the UI.
> 
> I've created game and match_game as pure models as they are part of the
> match creation.
> 
> So far, am i on the right track based on good practice and design?

If you have written your Cucumber stories and/or RSpec examples before 
all this work, using them to drive your design, then you are on the 
right track to good practice and design.

> One consideration i did have was whether, based on the fact that the
> maps and game_modes tables will always have a relatively small number of
> entries, i should just autogenerate the rows (20 in each table = 400
> rows. random generate a number between 1 and 400 and it picks the game).
> If i was to do this where would i embed the method to autopopulate the
> game table? (in the game model itself or a helper - i'm not sure on best
> practice). This could also be called if the admin decided to update the
> table with a new entry (i.e. it would create the extra matches needed).

The latest version of Rails has a convention for this, and an associated 
rake task. The feature is called "Seeds." You'll notice there will be a 
db/seeds.rb file for putting your Ruby code to populate your seed data. 
Then you can run rake db:seed after running rake db:migrate to execute 
the data seeds.

> At this stage i haven't even thought through how the actual UI will
> build all the bits and put them together but i'm thinking this would be
> the job of my match controller which creates a match object, x game
> objects and sets the 'games' property of the match object before
> committing the changes to the DB and letting rails do some magic to save
> it all (i'm not looking for someone to tell me as i'd like to work it
> out but if i'm way off track here then a pointer or 2 would be
> appreciated).

I would think that the controller would simply handled the request to 
"create" a new game:

matches_controller.rb
---------------------
def create
  @match = Match.new
  @match.start
  ...
  # Stuff to handle return the response
end

match.rb
---------------------
class Match << ActiveRecord::Base
  ...
  def start
    # Do all the stuff you need to do to start a match
  end
  ...
end

This is often referred to as "skinny controller, fat model design," and 
is typically promoted in Rails as a "best practice."
-- 
Posted via http://www.ruby-forum.com/.
-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.


Reply via email to