Rails newbie: How does the submit_tag work?

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:

<% javascript_include_tag "prototype" %>

<%= @quizrun.quiz.name %>

<%= @quizrun.user.name %>

Question <%= @question.seq %>

<%= @question.presentation.textvalue %>
<% if [email protected]? 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); -%> <% end end %>
Check Possible Answers
<%= submit_tag 'Next Question' %>

Hi David,

David J. 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

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 K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs