This project is archived and is in readonly mode.

#354 ✓resolved
Chris Cherry

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

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=""></a>


Referenced by