button_to

button_to(name, options = {}, html_options = nil)
public
Generates a form containing a sole button that submits to the URL given by options. Use this method instead of link_to for actions that do not have the safe HTTP GET semantics implied by using a hypertext link.
The parameters are the same as for link_to. Any html_options that you pass will be applied to the inner input element. In particular, pass
:disabled => true/false
as part of html_options to control whether the button is disabled. The generated form element is given the class ‘button-to’, to which you can attach CSS styles for display purposes.
Example 1:
# inside of controller for "feeds" button_to "Edit", :action => 'edit', :id => 3
Generates the following HTML (sans formatting):
<form method="post" action="/feeds/edit/3" class="button-to"> <div><input value="Edit" type="submit" /></div> </form>
Example 2:
button_to "Destroy", { :action => 'destroy', :id => 3 }, :confirm => "Are you sure?"
Generates the following HTML (sans formatting):
<form method="post" action="/feeds/destroy/3" class="button-to"> <div><input onclick="return confirm('Are you sure?');" value="Destroy" type="submit" /> </div> </form>
NOTE: This method generates HTML code that represents a form. Forms are "block" content, which means that you should not try to insert them into your HTML where only inline content is expected. For example, you can legally insert a form inside of a div or td element or in between p elements, but not in the middle of a run of text, nor can you place a form within another form. (Bottom line: Always validate your HTML before going public.)