Method: ActionView::Helpers::FormTagHelper#number_field_tag

Defined in:
actionpack/lib/action_view/helpers/form_tag_helper.rb

#number_field_tag(name, value = nil, options = {}) ⇒ Object

Creates a number field.

Options

  • :min - The minimum acceptable value.

  • :max - The maximum acceptable value.

  • :in - A range specifying the :min and :max values.

  • :step - The acceptable value granularity.

  • Otherwise accepts the same options as text_field_tag.

Examples

number_field_tag 'quantity', nil, :in => 1...10
=> <input id="quantity" name="quantity" min="1" max="9" />


583
584
585
586
587
588
589
590
# File 'actionpack/lib/action_view/helpers/form_tag_helper.rb', line 583

def number_field_tag(name, value = nil, options = {})
  options = options.stringify_keys
  options["type"] ||= "number"
  if range = options.delete("in") || options.delete("within")
    options.update("min" => range.min, "max" => range.max)
  end
  text_field_tag(name, value, options)
end