Keeping a running count of user input

(Start disclaimer) New to ruby, new to rails, haven't programmed since high school. (End disclaimer)

I am working on a personal project which I can use to track my golf scores and progress but am having difficult keeping a running count of the amount of holes played.

The app should work like this: 1. User starts the round - OK 2. Hole number is set to 1 - OK 3. User submits the first hole - OK 3a. Hole number is saved as 1 - OK 3b. Hole number increases by 1 - NOT OK 4. Redirect back to new - OK Repeat until hole number = 18

How can I create a variable which will store the hole number for the number of user inputs? Or should I write a loop which runs the input form # times?

Thanks for any advice.

(The basic code I am working off of is a (very) slightly modified scaffold)

You can store it in a session variable to keep track across requests session[:hole_number] = hole_number

Dan Ci wrote:

(Start disclaimer) New to ruby, new to rails, haven't programmed since high school. (End disclaimer)

I am working on a personal project which I can use to track my golf scores and progress but am having difficult keeping a running count of the amount of holes played.

The app should work like this: 1. User starts the round - OK 2. Hole number is set to 1 - OK 3. User submits the first hole - OK 3a. Hole number is saved as 1 - OK 3b. Hole number increases by 1 - NOT OK 4. Redirect back to new - OK Repeat until hole number = 18

That's a *very bad* user interface. The app should not force entry of holes in a particular order. Why not just provide a form for all 18 holes?

Best,

Marnen Laibow-Koser wrote:   Why not just provide a form for all 18

holes?

Holy verisimilitude Batman!!!

You mean a web page that looks like 99% of the golf score cards in use today?

Genius, sheer genius.

(no offense intended to anyone, just having fun)...

Ar Chron wrote:

Marnen Laibow-Koser wrote:   Why not just provide a form for all 18

holes?

Holy verisimilitude Batman!!!

You mean a web page that looks like 99% of the golf score cards in use today?

Genius, sheer genius.

I am always happy to impress. :smiley:

(no offense intended to anyone, just having fun)...

Best,

You can store it in a session variable to keep track across requests session[:hole_number] = hole_number

Thanks. I'm sure I'll find a way to mess that up.

Marnen Laibow-Koser wrote:

That's a *very bad* user interface. The app should not force entry of holes in a particular order. Why not just provide a form for all 18 holes?

I disagree, you start on the 1st and finish on the 18th so you should enter them in a particular order. Entering my data after I finish each hole is more natural.

The best way is probably just to write everything down while I am playing and then put it all in a spreadsheet, but then I wouldn't learn anything about programming.

Sharagoz -- wrote:

You can store it in a session variable to keep track across requests session[:hole_number] = hole_number

For the future reference of noobs like myself, this is how I did it. (For Agile Web Development with Rails readers, it's much easier than their Cart session would have you believe.)

def start #start the round   session[:hole_number] = 0   redirect_to(new) end

def new #modified scaffold   @hole = Hole.new   session[:hole_number] += 1   ... end

def create @modified scaffold   @hole = Hole.new(params[:hole])   @hole.hole_number = session[:hole_number]   ....other stuff...   redirect_to(new) end

Dan Ci wrote:

You can store it in a session variable to keep track across requests session[:hole_number] = hole_number

Thanks. I'm sure I'll find a way to mess that up.

Marnen Laibow-Koser wrote:

That's a *very bad* user interface. The app should not force entry of holes in a particular order. Why not just provide a form for all 18 holes?

I disagree, you start on the 1st and finish on the 18th so you should enter them in a particular order.

Don't force the user to do that.

Entering my data after I finish each hole is more natural.

For you. And the solution I suggested allows that -- but does not force it.

The best way is probably just to write everything down while I am playing and then put it all in a spreadsheet,

No. Spreadsheets really aren't the proper tool for *anything*.

but then I wouldn't learn anything about programming.

:slight_smile:

Best,