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 = {})
public
Generates a form containing a single button that submits to the URL created by the set of options. This is the safest method to ensure links that cause changes to your data are not triggered by search bots or accelerators. If the HTML button does not work with your layout, you can also consider using the link_to method with the :method modifier as described in the link_to documentation.
The generated form element has a class name of button_to to allow styling of the form itself and its children. You can control the form submission and input element behavior using html_options. This method accepts the :method and :confirm modifiers described in the link_to documentation. If no :method modifier is given, it will default to performing a POST operation. You can also disable the button by passing :disabled => true in html_options. If you are using RESTful routes, you can pass the :method to change the HTTP verb used to submit the form.
Options
The options hash accepts the same options as url_for.
There are a few special html_options:
- :method - Specifies the anchor name to be appended to the path.
- :disabled - Specifies the anchor name to be appended to the path.
- :confirm - This will use the unobtrusive JavaScript driver to prompt with the question specified. If the user accepts, the link is processed normally, otherwise no action is taken.
- :remote - If set to true, will allow the Unobtrusive JavaScript drivers to control the submit behaviour. By default this behaviour is an ajax submit.
Examples
<%= button_to "New", :action => "new" %> # => "<form method="post" action="/controller/new" class="button_to"> # <div><input value="New" type="submit" /></div> # </form>" <%= button_to "Delete Image", { :action => "delete", :id => @image.id }, :confirm => "Are you sure?", :method => :delete %> # => "<form method="post" action="/images/delete/1" class="button_to"> # <div> # <input type="hidden" name="_method" value="delete" /> # <input data-confirm='Are you sure?' value="Delete" type="submit" /> # </div> # </form>" <%= button_to('Destroy', 'http://www.example.com', :confirm => 'Are you sure?', :method => "delete", :remote => true, :disable_with => 'loading...') %> # => "<form class='button_to' method='post' action='http://www.example.com' data-remote='true'> # <div> # <input name='_method' value='delete' type='hidden' /> # <input value='Destroy' type='submit' disable_with='loading...' data-confirm='Are you sure?' /> # </div> # </form>" #