Reputation: 2495
My price column in my table is in type float.
I am trying to use the validates_numericality_of from the rails guide to doing some number validations.
This is the number text box from the form
<li>
<%=f.label :price, 'Asking Price:'%>
<%= f.number_field :price %><span class='columnLabel formtext'>USD</span>
</li>
I have this in the model
validates_numericality_of :price, :greater_than => 0
I want to make sure the price is a number, is positive, and can be a float and that it exist.
When I head to the form and try to enter 4.44, I keep on getting a pop up that says the nearest integer is 4 or 5 and I should enter valid values.
I have tried something like this too
validates_numericality_of :price, :only_integer => false
I do have this too
attr_accessible :city_id, :title, :price
so price can be mass assigned.
Upvotes: 2
Views: 823
Reputation: 5847
HTML5 number inputs only accepts integers by default.
Try f.number_field :price, step: 'any'
Upvotes: 1