Entering statistics

I have a huge form for users to enter statistics of their game, like a
golf scorecard.

How do I use select_tag to allow the users to enter the statistics to
their respective players on the two teams?

How would I go about this? Make a field an array?

I still can’t figure out what the best way to do this would be…

On Apr 8, 2008, at 1:44 PM, edberner wrote:

read this ed



Hmmm. Ok. I imagine this is going to be pretty hard to do but for each
scorecard there 14 options, three of which I’d like to keep but I want
the numbers to continually go up. So drop down 1 will be [ “blah”,
“blah”, “blah”, 1] drop down 2 assuming drop down 1 selected 1 will be
[ “blah”, “blah”, “blah”, 2] and so on. Also how do I enter this into
each respective Player’s model?

def update
@game = Game.find(params[:id])

for team in @game.teams
  for player in team.players
    player.hit_cups = params[:something???]
    player.total_shots = params[:player][????]

Can anybody please help?

I can help, but I’ll need you to explain the problem domain to me


Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)
VIDEO #3 out NOW!

A game has two teams and a team has three players. I just need a form
for each game with a drop box for each player each round to select
either miss or one through ten. Then let’s say I want to calculate the
cardinality of all the numbers ofthe total rounds. How would I do that?

On Apr 8, 2008, at 4:13 AM, Julian L. [email protected]

Haha still not enough?

Sorry, but I don’t understand what you mean.

You want me to tell you how to create a form for each game?

How many rounds in a game?

Is this dynamic, or not? How is it set up?

You leave far too many things open to interpretation.

What do you mean by “the cardinality of all the numbers of the total

Sorry, but I don’t play sports, and this makes little sense to me.


Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)
VIDEO #3 out NOW!

Again, this doesn’t make sense to me.

This is a vague shambles of a set of requirements. Please list
explicitly EXACTLY what you want to happen.

Then, I can help with that…

This is why you’re not getting any other responses.


Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)
VIDEO #3 out NOW!

A round is a field in the game model.

It’s set up in a table with a drop down menu including miss 1, 2, 3,
4, 5, 6, 7, 8, 9, 10
like this
team 1 with 3 players is on the left
team 2 is on the right with 3 players
a row is a round
for each round each player can do any one of the drop down menu items
(except no repeats for the numbers e.g. 1 can only be hit once.

so ultimately i’d like to be able to display for each player which
number they select or if they missed and how many times they missed.

I want exactly to be able to display a table with all the players
listed. For each column in this table I want statistics, like hit %,
points, etc. how these are derived is back logic and unimportant.

To do this the user must enter in the scorecard.
The scorecard looks like this when the user is done selecting the
values for miss/hit[1,10] It originally is blank.

---------------Team 1--------------------------------- Team
player 1, player 2, player3 ROUND player 1, player 2, player 3
-miss-------hit 1------hit2--------1-----------miss----miss -----miss

I’m assuming I use select_tag somehow…

Thanks Julian. Nice website by the way.

What don’t you understand?

Pretty much the whole lot. I don’t “get” your problem domain.

Like… what do you want help with?


Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)
VIDEO #3 out NOW!

A form

How do I setup the drop down menus in the view?
What do I write in the controller to add the value for each round into
the corresponding player.

Drop down menus are set up with the select or collection_select tags -
see the api for syntax.

I don’t know what you mean by “each round into the corresponding


Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)
VIDEO #3 out NOW!

there are a certain amount of rounds a game has, which is variable,
dependent on the game.

could you be more specific with select and collection_select the api
is kind of sparse.

Just so you know, this is quite annoying for me.

The API says:

collection_select(object, method, collection, value_method,
text_method, options = {}, html_options = {})

It takes:

an object (name as a string / symbol).

So, if in your controller, you have @user = User.find(params[:id])

Then this would be an example of the object to appear under the object
placeholder in the api.

rails will look for an instance variable (ie a variable starting with
@), which is named whatever you put in as the object placeholder


so far (and you must have @user set in corresponding action in the

This means, we want to set some attribute of this user. Let’s say the
collection_select is to select a group for this user.

So in our model, User belongs_to :group

This means there’s a group_id on the users table, and therefore a
group_id attribute in the User model, and on all our user objects from
then on in.

Thus, we’re interested in the “group_id” method of the user… this is
the attribute we’re going to set the value of in our database after
the person submitting the form has selected the option from the select

Now… therefore, we have:

collection_select(‘user’, ‘group_id’…

what this means is rails is going to be looking for a “group_id=”
method on the @user object… and because of the association, that’s
what we have.

The placeholder in collection_select is “collection”… this is the
collection from which to select the group_id (in this case).

Thus, we’ll need (here) a list of groups.

So in the controller, we’ll need to grab a list of groups

@groups = Group.find(:all)

will do the trick.

Now, our collection_select looks as follows:

collection_select(‘user’, ‘group_id’, @groups

The next two placeholders are value_method and text_method - these are
(in our instance) the group’s id (because that’s what value we want
set into the database on the @user’s group_id attribute), and the
group’s name (or whatever text value we want displayed to the person
selecting the items from the popup).

What it’s going to do is send EACH item of the @groups list these
methods to build the list of tags.

thus we now have:

collection_select(‘user’, ‘group_id’, @groups, ‘id’, ‘name’)

Now, there are two extra items (you’ll see), but because they have
equals signs in them, they’re illustrations of “defaulted” ones (ie
you don’t need to specify them).

as it is, the above will work just fine.

I hope this helps.

Perhaps I should do some sensei work on this, as it seems to be a very
common question :slight_smile:


Learn Ruby on Rails! Check out the FREE VIDS (for a limited time)
VIDEO #3 out NOW!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs