Topic: First project, need help setting up a Model.

I have completed most of the blog tutorials from the main rails site, but I got itchy to try out something on my own.

I am going to develop a little site which will allow me and my brother to record the results of the many games of FIFA we play.

I would like the site to allow me to create a new "Event" or "Games Session" and from within this event I woud be able to create new best-of-3 input fields, which would simply spawn a few input boxes to allow me to enter the scores for those games.

Should I initially have an Events model which has_many Game models?  Or should all of this fit into one model?

My next question is relating as to how I should best display this information.  I would ideally like to have everything work within one page, the creating of events would be merged with the viewing of existing events; I would be simply adding a new event to the top of the list of old ones.

Would this be a case of using partials for Event/new and Event/ to get them to display next to each other in a page?  Is this a good idea?

Would it be possible to have your opinion as to how you would approach this?

Thanks!

Last edited by SmokingKipper (2012-09-04 09:16:10)

Re: First project, need help setting up a Model.

From a db design point of view it seems like you want an event to have 3 games?
To achoeve this in your model relationships you would want a gae to belong to an event and an event to have many games
If you use accpets_nested_attributes_for declarations in your models in combination with fields_for declarations in your views with partials and a bit of ajax you can get this to work very nicely.

Have a look at this railscast. It should show you the way
http://railscasts.com/episodes/196-nest … orm-part-1

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: First project, need help setting up a Model.

Hi James, thanks a lot for the reply! I will look into the Rails casts link as soon as I can.

If I can just add something to my question.  An event would not just have 1 set of 3 games.  We generally play many sets of 3 games. 

I would need to be able to click a "new best of 3" button to decide to add another set of games to the database. but keep these within the specific event.

Would this still be the same as you described?  I just have the /new action triggered repeatedly for each time I click the button?

Last edited by SmokingKipper (2012-09-04 15:49:27)

Re: First project, need help setting up a Model.

jamesw wrote:

From a db design point of view it seems like you want an event to have 3 games?
To achoeve this in your model relationships you would want a gae to belong to an event and an event to have many games
If you use accpets_nested_attributes_for declarations in your models in combination with fields_for declarations in your views with partials and a bit of ajax you can get this to work very nicely.

Have a look at this railscast. It should show you the way
http://railscasts.com/episodes/196-nest … orm-part-1

Ha! They have a cast for everything, that Rails cast looks like it is going to be pretty much perfect for me smile

Thanks again (and from Leeds, not too far from Blackburn - crappy summer, eh?)

Last edited by SmokingKipper (2012-09-04 15:51:52)

Re: First project, need help setting up a Model.

Hi!
lol! Summer!!! What's that? smile
Watching Paralympics as well as Railscasts rocks!.
Welcome to Rails smile

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)