Skip to content

Instantly share code, notes, and snippets.

@rmaceissoft
Created March 20, 2012 00:33
Show Gist options
  • Save rmaceissoft/2129051 to your computer and use it in GitHub Desktop.
Save rmaceissoft/2129051 to your computer and use it in GitHub Desktop.
define fixed options for fields in a rails way
class Task < ActiveRecord::Base
# get an array with 0.0, 0.25, 0.50, 0.75, ...
@@hours_options = 0.step(3, 0.25).collect {|x| x}
belongs_to :proyect
# valudation rules
validates :hours, :inclusion => { :in => @@hours_options }
# helper to get hours options
def self.get_hours_options
@@hours_options.map{ |z| [z,z]}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment