Hi, I''m writing a small application, where Users can Register for a TrainingEvent to be trained in a certain Role. I have a form that contains radio boxes, one for every TrainingEvent. I also have a select box, one for every Role. The user must enter in a program number as well in this form. When the user doesn''t fill in a piece of information (i.e. the program number), I need to display the form again. However, the values that the user entered for the TrainingEvent and the Role are reset to their default values. How can I remember what the user selected? Thanks, Joe
Joe Van Dyk wrote:> Hi, > > I''m writing a small application, where Users can Register for a > TrainingEvent to be trained in a certain Role. > > I have a form that contains radio boxes, one for every TrainingEvent. > I also have a select box, one for every Role. The user must enter in > a program number as well in this form. > > When the user doesn''t fill in a piece of information (i.e. the program > number), I need to display the form again. However, the values that > the user entered for the TrainingEvent and the Role are reset to their > default values. How can I remember what the user selected?What does your view look like? Can you post it? Jeroen
On 12/8/05, Jeroen Houben <jeroen-aHd7JyfBtzlmR6Xm/wNWPw@public.gmane.org> wrote:> Joe Van Dyk wrote: > > Hi, > > > > I''m writing a small application, where Users can Register for a > > TrainingEvent to be trained in a certain Role. > > > > I have a form that contains radio boxes, one for every TrainingEvent. > > I also have a select box, one for every Role. The user must enter in > > a program number as well in this form. > > > > When the user doesn''t fill in a piece of information (i.e. the program > > number), I need to display the form again. However, the values that > > the user entered for the TrainingEvent and the Role are reset to their > > default values. How can I remember what the user selected? > > What does your view look like? Can you post it?<h1> Register For A Training Seminar</h1> <%= start_form_tag %> <b> Available Training events: </b> <br /> <table> <tr> <td> </td> <th> Location </th> <th> Hosting Chapter </th> <th> Registration Deadline </th> <th> Start Date </th> <th> End Date </th> <th> Spots Left </th> </tr> <tr> <td colspan=7> AVAILABLE TRAINING SEMINARS </td></tr> <% @available_training_events.each do |t| %> <tr> <td> <%= radio_button "registration", "training_event", t.id %> </td> <td> <%= t.location %> </td> <td> <%= link_to t.chapter.name, "" %> </td> <td> <%= t.registration_deadline.to_date %> </td> <td> <%= t.start_date.to_date %> </td> <td> <%= t.end_date.to_date %> </td> <td> <%= t.spots_left %> </td> </tr> <% end %> <tr> <td colspan=7> UNAVAILABLE TRAINING SEMINARS -- don''t register for these! </td></tr> <% @unavailable_training_events.each do |t| %> <tr> <td> </td> <td> <%= t.location %> </td> <td> <%= link_to t.chapter.name, "" %> </td> <td> <%= t.registration_deadline.to_date %> </td> <td> <%= t.start_date.to_date %> </td> <td> <%= t.end_date.to_date %> </td> <td> <%= t.spots_left %> </td> </tr> <% end %> </table> <br /> <p><%= text_field_tag "registration[program_number]" %> Program Number </p> <p><%= select "registration", "role", Role.find(:all).collect { |r| [r.name, r.id] } %> Role </p> <br /> <p><%= submit_tag %> </p> <%= end_form_tag %> And the controller: def register_for_training_seminar unless user? store_location redirect_to login_url end @registration = Registration.new @available_training_events = TrainingEvent.available_training_events @unavailable_training_events = TrainingEvent.find(:all) - @available_training_events if request.post? role = Role.find params[:registration][:role] training_event = TrainingEvent.find params[:registration][:training_event] @registration = Registration.new :user => current_user, :program_number => params[:registration][:program_number], :role => role, :training_event => training_event if @registration.save flash[:notice] = "Thanks for registering!" redirect_to :action => ''home'' else flash[:errors] = "Problem with registration: " flash[:errors] << "<br />" + @registration.errors.full_messages.join("<br />") end end end
On 12/8/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12/8/05, Jeroen Houben <jeroen-aHd7JyfBtzlmR6Xm/wNWPw@public.gmane.org> wrote: > > Joe Van Dyk wrote: > > > Hi, > > > > > > I''m writing a small application, where Users can Register for a > > > TrainingEvent to be trained in a certain Role. > > > > > > I have a form that contains radio boxes, one for every TrainingEvent. > > > I also have a select box, one for every Role. The user must enter in > > > a program number as well in this form. > > > > > > When the user doesn''t fill in a piece of information (i.e. the program > > > number), I need to display the form again. However, the values that > > > the user entered for the TrainingEvent and the Role are reset to their > > > default values. How can I remember what the user selected? > > > > What does your view look like? Can you post it?You can view the form at http://joevandyk.com/cisv/register_for_training_seminar (login with bob w/ password atest, or create a new user).
Joe Van Dyk wrote:> On 12/8/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >>On 12/8/05, Jeroen Houben <jeroen-aHd7JyfBtzlmR6Xm/wNWPw@public.gmane.org> wrote: >> >>>Joe Van Dyk wrote: >>> >>>>Hi, >>>> >>>>I''m writing a small application, where Users can Register for a >>>>TrainingEvent to be trained in a certain Role. >>>> >>>>I have a form that contains radio boxes, one for every TrainingEvent. >>>>I also have a select box, one for every Role. The user must enter in >>>>a program number as well in this form. >>>> >>>>When the user doesn''t fill in a piece of information (i.e. the program >>>>number), I need to display the form again. However, the values that >>>>the user entered for the TrainingEvent and the Role are reset to their >>>>default values. How can I remember what the user selected? >>> >>>What does your view look like? Can you post it? > > > You can view the form at > http://joevandyk.com/cisv/register_for_training_seminar (login with > bob w/ password atest, or create a new user).That''s currently throwing an error. Is it just happening after validation? Can yout strip out the validation and the redirect and see what happens? Jeroen
On 12/8/05, Jeroen Houben <jeroen-aHd7JyfBtzlmR6Xm/wNWPw@public.gmane.org> wrote:> Joe Van Dyk wrote: > > On 12/8/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > >>On 12/8/05, Jeroen Houben <jeroen-aHd7JyfBtzlmR6Xm/wNWPw@public.gmane.org> wrote: > >> > >>>Joe Van Dyk wrote: > >>> > >>>>Hi, > >>>> > >>>>I''m writing a small application, where Users can Register for a > >>>>TrainingEvent to be trained in a certain Role. > >>>> > >>>>I have a form that contains radio boxes, one for every TrainingEvent. > >>>>I also have a select box, one for every Role. The user must enter in > >>>>a program number as well in this form. > >>>> > >>>>When the user doesn''t fill in a piece of information (i.e. the program > >>>>number), I need to display the form again. However, the values that > >>>>the user entered for the TrainingEvent and the Role are reset to their > >>>>default values. How can I remember what the user selected? > >>> > >>>What does your view look like? Can you post it? > > > > > > You can view the form at > > http://joevandyk.com/cisv/register_for_training_seminar (login with > > bob w/ password atest, or create a new user). > > That''s currently throwing an error.Dang it, looks like the mysql timeout errors are still occuring on 0.14.4. :-( I''ll revert back to 0.14.3.> Is it just happening after validation? Can yout strip out the validation > and the redirect and see what happens?It happens whenever the page is displayed again, so not just after validation.
On 12/8/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12/8/05, Jeroen Houben <jeroen-aHd7JyfBtzlmR6Xm/wNWPw@public.gmane.org> wrote: > > Joe Van Dyk wrote: > > > On 12/8/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > >>On 12/8/05, Jeroen Houben <jeroen-aHd7JyfBtzlmR6Xm/wNWPw@public.gmane.org> wrote: > > >> > > >>>Joe Van Dyk wrote: > > >>> > > >>>>Hi, > > >>>> > > >>>>I''m writing a small application, where Users can Register for a > > >>>>TrainingEvent to be trained in a certain Role. > > >>>> > > >>>>I have a form that contains radio boxes, one for every TrainingEvent. > > >>>>I also have a select box, one for every Role. The user must enter in > > >>>>a program number as well in this form. > > >>>> > > >>>>When the user doesn''t fill in a piece of information (i.e. the program > > >>>>number), I need to display the form again. However, the values that > > >>>>the user entered for the TrainingEvent and the Role are reset to their > > >>>>default values. How can I remember what the user selected? > > >>> > > >>>What does your view look like? Can you post it? > > > > > > > > > You can view the form at > > > http://joevandyk.com/cisv/register_for_training_seminar (login with > > > bob w/ password atest, or create a new user). > > > > That''s currently throwing an error. > > Dang it, looks like the mysql timeout errors are still occuring on > 0.14.4. :-( I''ll revert back to 0.14.3. > > > Is it just happening after validation? Can yout strip out the validation > > and the redirect and see what happens? > > It happens whenever the page is displayed again, so not just after validation.Ok, reverted back to Rails 0.14.3, so http://joevandyk.com/cisv should be working again. Joe
> > Ok, reverted back to Rails 0.14.3, so http://joevandyk.com/cisv should > be working again. > > JoeI can see it now. The form looks ok to me. The code in the controller looks a bit overly complex. Can you put <%= debug @registration %> in your form? This way you can easily tell what values are assigned to the model. I think if you have your assoications setup right, you should just be able to do @registration = Registration.new(params[:registration] J
On 12/8/05, Jeroen Houben <jeroen-aHd7JyfBtzlmR6Xm/wNWPw@public.gmane.org> wrote:> > > > > Ok, reverted back to Rails 0.14.3, so http://joevandyk.com/cisv should > > be working again. > > > > Joe > > I can see it now. The form looks ok to me. The code in the controller > looks a bit overly complex. > > Can you put > > <%= debug @registration %> in your form? This way you can easily tell > what values are assigned to the model. > > I think if you have your assoications setup right, you should just be > able to do > > @registration = Registration.new(params[:registration]Currently, the relationships look like: Registration belongs_to User Registration belongs_to Role Registration belongs_to TrainingEvent TrainingEvent has_many Registrations User has_many Registrations Role has_many Registrations And Registration also has other data, like program_number, modified_on, created_on, roommate preference, etc. So I don''t think I can just do a @registration Registration.new(params[:registration])... but I could be wrong. I''ll try it out this evening.
On 12/8/05, Joe Van Dyk <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 12/8/05, Jeroen Houben <jeroen-aHd7JyfBtzlmR6Xm/wNWPw@public.gmane.org> wrote: > > > > > > > > Ok, reverted back to Rails 0.14.3, so http://joevandyk.com/cisv should > > > be working again. > > > > > > Joe > > > > I can see it now. The form looks ok to me. The code in the controller > > looks a bit overly complex. > > > > Can you put > > > > <%= debug @registration %> in your form? This way you can easily tell > > what values are assigned to the model. > > > > I think if you have your assoications setup right, you should just be > > able to do > > > > @registration = Registration.new(params[:registration] > > Currently, the relationships look like: > Registration belongs_to User > Registration belongs_to Role > Registration belongs_to TrainingEvent > > TrainingEvent has_many Registrations > User has_many Registrations > Role has_many Registrations > > And Registration also has other data, like program_number, > modified_on, created_on, roommate preference, etc. > > So I don''t think I can just do a @registration > Registration.new(params[:registration])... but I could be wrong. I''ll > try it out this evening.Nope, I can''t. Anyone have any ideas on how I can get the radio box selection to persist if there''s a validation error?