Nuclear Rooster

15Apr/101

Datamapper validate_within syntax

I had to dig into the code to figure this one out, a practice which I am finding both more common and convenient, but it is always second to a quick google search. So, here it is, a validates_within example for Datamapper:


class Essay
  include DataMapper::Resource

  property :id, Serial
  property :rating, Integer, :set => 0..5 #inline validation
  property :technical_score, Integer
  property :style_score, Integer

  # Validation for multiple properties
  validates_within :technical_score, :style_score, :set => 0..100
end