I would appreciate any and all input. The Agile book is not useful in this context. :o( As near as I can tell, it doesn''t work at all. I would expect that clicking on the [Next Question] button in the browser would fire the next_question method in the current controller. Instead, it (apparently) does nothing. The tag in question <%= submit_tag ''Next Question'' %> expands to <input name="next_question" type="submit" value="Next Question" /> RHTML follows: --------------------------------------------- <head><% javascript_include_tag "prototype" %></head> <SCRIPT LANGUAGE="JavaScript"> <!-- Beginning of JavaScript - function checkboxClick(element) { inputValue = element.firstChild if (inputValue.getAttribute ("value") == "off") { inputValue.setAttribute ("value", "on") element.setAttribute ("background","/images/cbChecked.png"); } else { inputValue.setAttribute ("value", "off") element.setAttribute ("background","/images/cbUnchecked.png"); } } // - End of JavaScript - --> </SCRIPT> <h1><%= @quizrun.quiz.name %></h1> <h2><%= @quizrun.user.name %></h2> <table> <tr><td><h3>Question <%= @question.seq %></h3></td></tr> <tr><td><%= @question.presentation.textvalue %></td></tr> </table> <table cellpadding="3" cellspacing="0" id="answersTable"> <thead> <tr> <td></td> <td>Check</td> <td></td> <td>Possible Answers</td> </tr> </thead> <tbody id="answersBody"> <% if !@question.id.nil? answers = Answers.find (:all, :conditions => "parent_id = " + @question.id.to_s) for answer in answers presentation = Presentations.find_by_id (answer.presentation_id.to_s); -%> <tr> <td><input type="hidden" name="answerId[]" value="<%= answer.id %>"/></td><td background="<%= ''/images/cbUnchecked.png'' %>" onClick="checkboxClick(this)"><input type="hidden" name="iscorrect[]" value="off" style="background-repeat: no-repeat"/></td> <td><input type="hidden" size="3" name="answerPoints[]" value="<%answer.points %>"/></td> <td><input type="text" name="presentationtext[]" value="<%presentation.textvalue %>"/></td> </tr> <% end end %> </tbody> <tfoot> <tr> <td colspan="2"><%= submit_tag ''Next Question'' %></td> </tr> </tfoot> </table>
This is actually an HTML question. The method and controller that receives your form submission is determined by the action in the form start tag. Look at form_tag. <http://api.rubyonrails.com/classes/ ActionView/Helpers/FormTagHelper.html#M000491>. You can have multiple submit buttons, but they just return name/value pairs like other form objects. As an example, the following in a edit.rhtml submits the form to the update method of the same controller: <%= form_tag :action => ''update'', :id => ''update_form'' %> - dan -- Dan Kohn <mailto:dan@dankohn.com> <http://www.dankohn.com/> <tel:+1-415-233-1000> On Jul 13, 2006, at 7:58 PM, David Johnson wrote:> I would appreciate any and all input. The Agile book is not useful in > this context. :o( > > As near as I can tell, it doesn''t work at all. > > I would expect that clicking on the [Next Question] button in the > browser would fire the next_question method in the current controller. > > Instead, it (apparently) does nothing. > > > The tag in question > > <%= submit_tag ''Next Question'' %> > > expands to > > <input name="next_question" type="submit" value="Next > Question" /> > > > > RHTML follows: > --------------------------------------------- > > <head><% javascript_include_tag "prototype" %></head> > <SCRIPT LANGUAGE="JavaScript"> > <!-- Beginning of JavaScript - > > function checkboxClick(element) { > inputValue = element.firstChild > > if (inputValue.getAttribute ("value") == "off") > { > inputValue.setAttribute ("value", "on") > element.setAttribute ("background","/images/cbChecked.png"); > } > else { > inputValue.setAttribute ("value", "off") > element.setAttribute ("background","/images/cbUnchecked.png"); > } > } > > > // - End of JavaScript - --> > </SCRIPT> > > <h1><%= @quizrun.quiz.name %></h1> > <h2><%= @quizrun.user.name %></h2> > > <table> > <tr><td><h3>Question <%= @question.seq %></h3></td></tr> > <tr><td><%= @question.presentation.textvalue %></td></tr> > </table> > > <table cellpadding="3" cellspacing="0" id="answersTable"> > <thead> > <tr> > <td></td> > <td>Check</td> > <td></td> > <td>Possible Answers</td> > </tr> > </thead> > > <tbody id="answersBody"> > <% > if !@question.id.nil? > answers = Answers.find (:all, :conditions => "parent_id = " + > @question.id.to_s) > for answer in answers > presentation = Presentations.find_by_id > (answer.presentation_id.to_s); > -%> > <tr> > <td><input type="hidden" name="answerId[]" value="<%= > answer.id % >> "/></td> > <td background="<%= ''/images/cbUnchecked.png'' %>" > onClick="checkboxClick(this)"><input type="hidden" name="iscorrect[]" > value="off" style="background-repeat: no-repeat"/></td> > <td><input type="hidden" size="3" name="answerPoints[]" > value="<%> answer.points %>"/></td> > <td><input type="text" name="presentationtext[]" value="<%> presentation.textvalue %>"/></td> > </tr> > <% end > end > %> > > </tbody> > <tfoot> > <tr> > <td colspan="2"><%= submit_tag ''Next Question'' %></td> > </tr> > </tfoot> > </table> > > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails
Hi David, David Johnson wrote:> > I would expect that clicking on the > [Next Question] button in the browser > would fire the next_question method in > the current controller. > > Instead, it (apparently) does nothing.Rails is a lot easier than this. The submit or submit_tag methods in Rails work in the context of a form or form_tag. The code you provided has neither. hth, Bill
Thanks (both of you) I knew it was a newbie question. Learning rails involves four new programming languages (ruby, html, rhtml tag libs, and javascript), plus a different programming paradigm. I''m on the right track now. On Thu, 2006-07-13 at 22:21 -0500, Bill Walton wrote:> Hi David, > > David Johnson wrote: > > > > I would expect that clicking on the > > [Next Question] button in the browser > > would fire the next_question method in > > the current controller. > > > > Instead, it (apparently) does nothing. > > Rails is a lot easier than this. The submit or submit_tag methods in Rails > work in the context of a form or form_tag. The code you provided has > neither. > > hth, > Bill > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails