About

This is my personal blog where I like to blog about technology and other interesting stuff in life.

Today I was trying to figure out how to validate if a user entered a number in a given set. I searched the internet high and low and could only figure out how to validate a range. I actually found the solution in a book, so I thought I would post it.

1
2
3
4
5
6
class Story < ActiveRecord::Base
  validates_presence_of :name, :description
  validates_inclusion_of :storypoints, :in=>[1,2,3,5,8,13], :
          message =>"Story Points must be 1,2,3,5,8 or 13"
  belongs_to :sprint
end

Leave a Reply