Deciml

Hi
In my table I have
t.decimal :rent, :precision => 12, :scale => 2

But when ever I enter a large value like

1234567890333.465

To the table it is stored as 9999999999.99

     I would like to know how active record validation can be

applied here?

Thanks
Tom

On 5 April 2010 09:54, Tom M. [email protected] wrote:

applied here?
Have a look at the rails guide on validations at
http://guides.rubyonrails.org. Particularly validates_numericality_of
which allows a range of values to be specified.

Colin

Hi,
When you set field to decimal than default it accept 10 digits. so
when you add the value over the limit it set to maximum decimal value.

 Add two validation in this case:

 a. validates_length_of - for length of decimal
 b. validates_numericality_of - for digits only

Hi
Thanks for all your reply

Tom

On 5 April 2010 12:54, Priyanka P. [email protected] wrote:

Hi,
When you set field to decimal than default it accept 10 digits. so
when you add the value over the limit it set to maximum decimal value.

Add two validation in this case:

a. validates_length_of - for length of decimal
b. validates_numericality_of - for digits only

If validates_numericality_of is used with :less_than (and probably
:more_than) then I think the length_of test is not necessary.

Colin

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs