Another rails/web newbie question. I have a single form defined like this... <%= start_form_tag :action => ''goto_next_question'' %> <%= render_partial ''test_question'' %> <%= submit_tag ''Continue'' %> <%= end_form_tag %> This is part of a testing/quizzing application I''m working on. As the user is taking a test, pressing the "Continue" button submits the form to the controller''s goto_next_question method which saves the existing record and loads in the next question. This is all working fine. But what if I want to have a numbered list of all the questions at the bottom or top of the page, kind of google-style... << 1 2 3 4 5 6 7 >> ... where each number is a link to a test question. How should I create the links so that clicking a numbered link will submit the form, not to the goto_next_question action like the "Continue" button does, but to goto_specific_question, which would return whichever question the user clicked on. <%= link_to "1", {:action => ''goto_specific_question'', :id => question} %> This link takes me to the right action/question, but does not submit the form. Any guidance would be much appreciated.
Joe Lester wrote:> Another rails/web newbie question. I have a single form defined like > this... > > <%= start_form_tag :action => ''goto_next_question'' %> > <%= render_partial ''test_question'' %> > <%= submit_tag ''Continue'' %> > <%= end_form_tag %> > > This is part of a testing/quizzing application I''m working on. As the > user is taking a test, pressing the "Continue" button submits the form > to the controller''s goto_next_question method which saves the existing > record and loads in the next question. This is all working fine. > > But what if I want to have a numbered list of all the questions at the > bottom or top of the page, kind of google-style... << 1 2 3 4 5 > 6 7 >> ... where each number is a link to a test question. How should > I create the links so that clicking a numbered link will submit the > form, not to the goto_next_question action like the "Continue" button > does, but to goto_specific_question, which would return whichever > question the user clicked on.Use multiple submit tags. You will get the text of the submit tag on which the user has clicked back in the value of the :commit key in params. <%= start_form_tag :action => ''goto_question'' %> <%= render_partial ''test_question'' %> <%= submit_tag ''Continue'' %> <%= submit_tag ''1'' %> <%= submit_tag ''2'' %> <%= submit_tag ''3'' %> <%= submit_tag ''4'' %> <%= submit_tag ''5'' %> <%= end_form_tag %> If you wish to send back a different value for commit, override like this: <%= submit_tag ''Continue'', ''value'' => @current_question+1 %>
But if you want the links to other questions to look like normal links rather than buttons or images you''ll have to use an onclick function on the links to both diddle the value of either the submit button or a hidden control and activate the form submit event.
I got "onclick" to work, as you suggested, to toggle a hidden control and submit the form. Thanks. On Aug 10, 2005, at 7:23 PM, Mark Reginald James wrote:> But if you want the links to other questions to look like normal > links rather than buttons or images you''ll have to use an onclick > function on the links to both diddle the value of either the submit > button or a hidden control and activate the form submit event.