Ruby on Rails: how to set size of number_field

I was using number_field_tag and I had to add empty braces for second parameter when I was not using value.

number_field_tag(name, value = nil, options = {})

This is what documentation says and I did not use value so my code with max looks like this

<%= number_field_tag :name,{}, max: @max_amount %>


You need to use :max option.

<%= f.number_field :name, max: 10, .. %>

Read the documentation number_field_tag.

number_field_tag(name, value = nil, options = {})

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.


<%= form.number_field :n, {min: 0, max: 99} %>

This tag has not any syntax error.