On Sep 16, 12:34 pm, Dave Howell <[email protected]> wrote: > On Sep 16, 2010, at 9:01 , Jeremy Evans wrote: > > >> >> c.batch_id="375a4e3c-5fc1-11df-94f7-00065b3f562c" > >> => "375a4e3c-5fc1-11df-94f7-00065b3f562c" > >> >> c.valid? > >> => true > > >> What? But .percentage isn't even defined yet . . . > >> I cannot figure out why the validation system is correctly monitoring the > >> two _id parameters, but completely ignoring the percentage. > > > I can't replicate this: > > And well you shouldn't. I apologize for being a dummkopf and wasting your > time. > > It seems, a few weeks ago, I'd been perplexed by getting back this > 'BigDecimal" type which kept formatting in an exasperatingly useless way, so > I'd added > > def percentage > super.to_f > end > > to the definition of the Component model. I'm not sure if that code even > accomplished anything, but it certainly messed up the validation code. > > Removing it has solved the problem.
That makes sense, as super would return nil, nil.to_f is 0.0, and 0.0 is both not nil (passing presence) and a number (passing numeric). If you really want to deal with percentage as a float, you should probably be using a double precision type in the database. You are probably using a decimal or numeric type in the database, and the only appropriate ruby type is BigDecimal, as Float does not support arbitrary precision (it has about 15 significant digits). Jeremy Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sequel-talk?hl=en.
