Strange numeric validation problem in ActiveRecord


I am trying to do validation in an ActiveRecord object.

I have a field called replay_limit. Here is what happens when the web page user fills in invalid data into replay_limit (which is declared as an integer in Mysql):

I do puts in the validate routine to show its class and value. Note that it is a Fixnum, and it has a value of 6. Yet, the to_yaml shows what the user really entered: 6#, which I would like to access in the validate routine, and return an error.

How can things get in this situation? How can I get at the real "string" value of what the user entered?

self.replay_limit.class = Fixnum self.replay_limit = 6

--- &id001 !ruby/object:Service attributes:   activation_pin: "32990"   sms_text: ""   service_options: 32   moderator_id: "0"   replay_limit: 6#

Also, why isn't there quotes around the 6# that to_yaml outputs?



What is service_options in mysql (int, float, etc)?


validates_numericality_of :replay_limit, :only_integer => true

The field service_options is int.

Unfortunately, the validates_numericality_of does not work properly. It does not detect always invalid data. I saw indications of bug reports in this area.

I did find the solution however. I need to use the <attribute>_before_type_cast method. In my case, replay_limit_before_type_cast. When I use that method, I can see what the user actually entered.