hi, i'm very new to ruby and rails so be gentle. i am trying to set up
a form that uses some validation but i'm having issues. i have a
controller class that contains 2 methods: one for showing the form and
another for processing the form. like so:
def show_form
store = Store.find_by_id(session[:store_id])
@all_balls = store.balls
@ball_sizes = store.ball_sizes
end
def complete_form
@picked_ball = session[:picked_ball]
if check_nil @picked_bread, 'Please choose a ball.'
return
end
@picked_ball_size = session[:picked_ball_size]
if check_nil @picked_ball_size, 'Please choose a ball size.'
return
end
# save stuff off into db
end
def check_nil(var_to_check, message)
if var_to_check.nil?
flash[:notice] = message
redirect_to :back
return true
end
false
end
my problem is that if the user selects a ball but forgets to select a
ball size, i go back to the form but it seems that i've lost all memory
of @picked_ball. i don't want to user to have to select the ball again.
i want it to be selected when the page is redisplayed with the error.
do i have to put this stuff in the session? i hope i don't because
there are actually a lot more items on the page, i've cut it down so my
post isn't quite as long.
also, here is my form:
<% form_tag(:action => 'complete_form') do %>
<h3>balls</h3>
<% for ball in @all_balls %>
<%= radio_button_tag 'picked_ball', ball.name, @picked_ball ==
ball.name %> <%= ball.name %><br />
<% end %>
<% for size in @all_sizes %>
<%= radio_button_tag 'picked_size', size.name, @picked_size ==
size.name %> <%= size.name %><br />
<% end %>
<% end %>
thanks for any and all help.
-peter
--
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
-~----------~----~----~----~------~----~------~--~---