(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)
(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?
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.
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