Forms send the name/value pairs of all the input elements to the server.
Forms also send the name/value of the button that was clicked. If you
examine the railscast screenshot where he is checking the log to see
what the checkbox parameters are being sent in the request, you will
also see this parameter:
''commit'' => ''Mark as Complete''
''Mark as Complete'' is the text on the button, so you can
deduce that
must be a name/value pair for the button. If ''Mark as
Complete'' is the
value, what is the name part of that name/value pair? Answer:
''commit''.
Where does the name ''commit'' come from? IN the railscast he
never names
the button--all he does is write this:
<%= submit_tag "Mark as Complete" %>
But if you check the docs for submit_tag(), rails give the button the
name ''commit''.
If you name all your buttons ''commit'', then in your action to
determine
what button was clicked, all you have to do is write:
case params[:commit]
when "text on button1"
#do something
when "text on button2"
#do something else
when "Mark as Complete"
#do that
else
#Error
end
--
Posted via http://www.ruby-forum.com/.
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.