The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
What's New in Edge Rails: validates_numericality_of Gets Pimped

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
rwdaigle

Posts: 312
Nickname: rwdaigle
Registered: Feb, 2003

Ryan is a passionate ruby developer with a strong Java background.
What's New in Edge Rails: validates_numericality_of Gets Pimped Posted: May 29, 2007 5:42 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by rwdaigle.
Original Post: What's New in Edge Rails: validates_numericality_of Gets Pimped
Feed Title: Ryan's Scraps
Feed URL: http://feeds.feedburner.com/RyansScraps
Feed Description: Ryan Daigle's various technically inclined rants along w/ the "What's new in Edge Rails" series.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by rwdaigle
Latest Posts From Ryan's Scraps

Advertisement

validates_numericality_of just got a shot of mojo this weekend in the form of some highly useful options.

Prior to this recent change, your numerical validation options were limited to only_integer and allow_nil. Any desires to do anything slightly more complex meant dropping down into your own validation routine. Now, some of the more common validations one might want on a number parameter have been option-ized, including:
  • greater_than
  • greater_than_or_equal_to
  • equal_to
  • less_than
  • less_than_or_equal_to
  • odd
  • even

Which allows us to do things such as:

1
2
3
4
validates_numericality_of :salary, :greater_than_or_equal_to => 40000
validates_numericality_of :ten, :equal_to => 10
validates_numericality_of :bonus, :less_than => 5000
validates_numericality_of :prime, :odd => true

So put away that crusty custom validate and plug into these fresh validation options. Guaranteed to make your life easier.

tags: ruby, rubyonrails

Read: What's New in Edge Rails: validates_numericality_of Gets Pimped

Topic: New Lifestyle? Previous Topic   Next Topic Topic: Flip Video Camcorder

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use