Steve Jorgensen
2013-Jan-14 05:14 UTC
How about a :without_type_cast => true option for validations?
One of the annoying problems with validations is that they are always applied after typecasting. This means, for instance, that the :only_integer option is effectively a no-op for an integer AR attribute. Whatever digits the user thought they were entering have already been lost before the validation can see the problem. This can be worked around, but it''s awkward and kludgey. A clean way to handle this would be to have a :before_type_cast option that runs the validation against the <attr>_before_type_cast attribute, but still associates the error with the regular attribute. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-core/-/kdxsmO1fjz0J. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
Godfrey Chan
2013-Jan-14 05:36 UTC
Re: How about a :without_type_cast => true option for validations?
I would love to see this happen, I remember I had to do something like that for a few times in the past. On Sunday, January 13, 2013, Steve Jorgensen wrote:> One of the annoying problems with validations is that they are always > applied after typecasting. This means, for instance, that the :only_integer > option is effectively a no-op for an integer AR attribute. Whatever digits > the user thought they were entering have already been lost before the > validation can see the problem. This can be worked around, but it''s awkward > and kludgey. > > A clean way to handle this would be to have a :before_type_cast option > that runs the validation against the <attr>_before_type_cast attribute, but > still associates the error with the regular attribute. > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Core" group. > To view this discussion on the web visit > https://groups.google.com/d/msg/rubyonrails-core/-/kdxsmO1fjz0J. > To post to this group, send email to rubyonrails-core@googlegroups.com<javascript:_e({}, ''cvml'', ''rubyonrails-core@googlegroups.com'');> > . > To unsubscribe from this group, send email to > rubyonrails-core+unsubscribe@googlegroups.com <javascript:_e({}, ''cvml'', > ''rubyonrails-core%2Bunsubscribe@googlegroups.com'');>. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-core?hl=en. >-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.