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 -- Posted via ruby-forum.com. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
On 5 April 2010 09:54, Tom Mac <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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?Have a look at the rails guide on validations at guides.rubyonrails.org. Particularly validates_numericality_of which allows a range of values to be specified. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
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 -- Posted via ruby-forum.com. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
On 5 April 2010 12:54, Priyanka Pathak <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> 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 onlyIf validates_numericality_of is used with :less_than (and probably :more_than) then I think the length_of test is not necessary. Colin> -- > Posted via ruby-forum.com. > > -- > You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. > To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. > For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en. > >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.
Hi Thanks for all your reply Tom -- Posted via ruby-forum.com. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at groups.google.com/group/rubyonrails-talk?hl=en.