dtrusty-U6r7FCv0h4VBDgjK7y7TUQ@public.gmane.org
2008-Jan-23 18:35 UTC
Strange numeric validation problem in ActiveRecord
Hi, 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? Thanks, David --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
What is service_options in mysql (int, float, etc)? anyways... validates_numericality_of :replay_limit, :only_integer => true -- Posted via http://www.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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
dtrusty-U6r7FCv0h4VBDgjK7y7TUQ@public.gmane.org
2008-Jan-24 16:43 UTC
Re: Strange numeric validation problem in ActiveRecord
On Jan 24, 2:18 am, Keynan Pratt <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> What is service_options in mysql (int, float, etc)? > > anyways... > > validates_numericality_of :replay_limit, :only_integer => true > -- > Posted viahttp://www.ruby-forum.com/.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. Thanks, David --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---