Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails: how to set size of number_field

Could someone show me how to set the size of number_field in rails? I tried this but it doesn't work:

<%= f.number_field :status, size: "10", ...

but this works:

<%= f.text_field :name, size: "10", ...

Thanks

like image 780
vvofdcx Avatar asked Jan 25 '15 07:01

vvofdcx


2 Answers

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.

like image 156
Arup Rakshit Avatar answered Sep 23 '22 16:09

Arup Rakshit


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

This tag has not any syntax error.

like image 25
hobbydev Avatar answered Sep 22 '22 16:09

hobbydev