Rails number_field ignoring requirements in haml view

I have the following code in my view

.fields
   = f.label :minimum_mpg
   %br
   = f.number_field :mpg_min, :in => 0..100, :type => 'float' , :precision => 2

I want to restrict the input from 0 to 100, but when I enter in negative numbers they are accepted. I think it has something to do with changing the type to float. The input needs to be able to accept floats though.

Thanks for you help.

Answers


Your :type => 'float' line is overriding the default type="number" part of the HTML tag that is generated, effectively turning it back into a standard text field instead of a number field.

If you need to accept two decimal places, you could do something like this. However, clicking the up/down arrows on the field will only increment 0.01 at a time.

= f.number_field :mpg_min, :in => 0..100, :step => 0.01

Need Your Help

Android Facebook SDK 4.4.1 - ShareApi.share(...) makes 3 requests

android facebook facebook-graph-api android-facebook

Today I updated our Android Facebook SDK to the latest version (4.4.1). I'm now seeing some odd behavior.

Problem: Movie Clip contains just one frame

flash flash-cs4

I'm a newbie at Flash, so started playing with a pretty standard code sample: one layer contains a movie clip with a flying rectangle, another layer has a button to control it. All script code is i...