This project is archived and is in readonly mode.
Allow Infinity to pass validates_numericality_of
Reported by Chris Cherry | June 6th, 2008 @ 07:38 AM
This patch allows a getter method on a model to return infinity and still pass validates_numericality_of.
This patch has been running in a production app since January 2008.
Why is Infinity useful?
Ruby's Infinity (1.0/0.0) can be very useful when implementing "limits" in a model. For example a package for an account might have a page_limit specifying how many pages a user might be able to create. If you wish to support "unlimited" size packages you might allow page_limit to be stored as a NULL in the database, and have a getter method that returns Infinity when the attribute is nil. This allows you to use the attribute directly in comparisons and other kinds of basic math like "remaining pages" without needing conditional logic.
Comments and changes to this ticket
-
shuber June 6th, 2008 @ 10:29 PM
Seems like it could be pretty useful in some situations.
Applied the patch, works as expected and all tests pass.
+1
-
Lytol June 18th, 2008 @ 07:45 AM
+1 Putting mathematical debates aside (since infinity is not a number), I can see the usefulness of this functionality. Tests pass... let's see what others have to say. With mathematical theory aside, a pretty clever solution. =)
-
Chris Cherry June 18th, 2008 @ 10:35 PM
- no changes were found...
-
Repository July 9th, 2008 @ 01:25 PM
- State changed from new to resolved
- Tag set to patch, tiny, verified
(from [124d1016fa212c008e33853912493fa9ac15d086]) Allow Infinity (1.0/0.0) to pass validates_numericality_of. [#354 state:resolved]
Signed-off-by: Pratik Naik
-
Repository July 15th, 2008 @ 11:56 PM
(from [d12660022525b9b1e25b92cd4639e32c8608f729]) Allow Infinity (1.0/0.0) to pass validates_numericality_of. [#354 state:resolved]
Signed-off-by: Pratik Naik
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 2780 Support for infinity from database in validates_numericality_of https://rails.lighthouseapp.com/projects/8994/tickets/35...