button_to
- 1.0.0 (0)
- 1.1.6 (0)
- 1.2.6 (-1)
- 2.0.3 (14)
- 2.1.0 (0)
- 2.2.1 (0)
- 2.3.8 (0)
- 3.0.0 (20)
- 3.0.9 (0)
- 3.1.0 (13)
- 3.2.1 (10)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (33)
- 4.1.8 (8)
- 4.2.1 (-5)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (38)
- 7.1.3.2 (-8)
- 7.1.3.4 (0)
- What's this?
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.)