method
button_tag
v7.2.3 -
Show latest stable
- Class:
ActionView::Helpers::FormTagHelper
button_tag(content_or_options = nil, options = nil, &block)public
Creates a button element that defines a submit button, reset button or a generic button which can be used in JavaScript, for example. You can use the button tag as a regular submit tag but it isn’t supported in legacy browsers. However, the button tag does allow for richer labels such as images and emphasis, so this helper will also accept a block. By default, it will create a button tag with type submit, if type is not given.
Options
-
:data - This option can be used to add custom data attributes.
-
:disabled - If true, the user will not be able to use this input.
-
Any other key creates standard HTML options for the tag.
Examples
button_tag # => <button name="button" type="submit">Button</button> button_tag 'Reset', type: 'reset' # => <button name="button" type="reset">Reset</button> button_tag 'Button', type: 'button' # => <button name="button" type="button">Button</button> button_tag 'Reset', type: 'reset', disabled: true # => <button name="button" type="reset" disabled="disabled">Reset</button> button_tag(type: 'button') do content_tag(:strong, 'Ask me!') end # => <button name="button" type="button"> # <strong>Ask me!</strong> # </button>