I have an HTML.erb file that defines 2 text_area_tags (input, output)
and 3 submit_to_remote buttons (rewrite, demo, clear). Depending on
which button is clicked, I’d like to call the corresponding Ruby method
on the server and then update the web page. My problem is that, no
matter which button is clicked, the same method (input_output) is always
called. I thought I could set the :action within the button definition
to specify the method to call, but it looks like the :action specified
in the form will always be called. How can I make each button call a
different method? Alternatively, how can I display the name of the
button that was clicked within the method that is being called? The
html.erb file is below. Thank you in advance for your help.
<div id="input_output_form">
<% form_tag(:action=>:input_output) do %>
<%= text_area_tag(:input, params[:input], :size=>"80x11") %>
<p></p>
<%= submit_to_remote 'Rewrite','Rewrite',
:action=>'rewrite',
:update=>'input_output_form',
:html=>{:class=>"btn",
:onmouseover=>"this.className='btn btnhov'",
:onmouseout=>"this.className='btn'"} %>
<%= submit_to_remote 'Demo','Demo',
:action=>:demo,
:update=>'input_output_form',
:html=>{:class=>"btn",
:onmouseover=>"this.className='btn btnhov'",
:onmouseout=>"this.className='btn'"} %>
<%= submit_to_remote 'Clear','Clear',
:action=>':clear',
:update=>'input_output_form',
:html=>{:class=>"btn",
:onmouseover=>"this.className='btn btnhov'",
:onmouseout=>"this.className='btn'"} %>
<p></p>
<%= text_area_tag(:output, params[:output], :size=>“80x11”) %>
<%= text_area_tag(:scratchpad, params[:scratchpad], :size=>“80x11”) %>
<% end %>
</div>