ruby on rails - validation before attribute setters can type cast -


i have object attribute called value of type big decimal. in class definition have validates_numericality_of.

however if i:

a.value = 'fire' 

'fire' ends getting typecast correct type before validation fires so:

a.valid? => true 

how validation fire before typecast?

thanks

dan

from activerecord::base docs:

sometimes want able read raw attribute data without having column-determined typecast run course first. can done using <attribute>_before_type_cast accessors attributes have. example, if account model has balance attribute, can call account.balance_before_type_cast or account.id_before_type_cast.

this useful in validation situations user might supply string integer field , want display original string in error message. accessing attribute typecast string 0, isn’t want.


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -