How to do date, datefields, datetime like 30boxes

The following are some links to do natural language date selection with rails. I recommend going ahead and using chronic, but take a look at Ryan Bates solution for good measure.

semi-solution - date-time-text-field-helpers

Ryan bates solution - this guy is the man

Ruby Chronic

Comments

  1. Scott Motte | August 27, 2008

    require ‘chronic’
    class Service < ActiveRecord::Base
    belongs_to :location
    belongs_to :obituary
    validates_presence_of :name

    def before_save
    self.start_time = Chronic.parse(self.start_time_before_type_cast) if self.start_time_before_type_cast
    self.end_time = Chronic.parse(self.end_time_before_type_cast) if self.end_time_before_type_cast
    end

    protected
    def validate
    errors.add(:location_id, “can’t be blank”) if location_id.blank?
    errors.add :start_time, ‘is not a valid date. Try removing any commas.’ if Chronic.parse(start_time_before_type_cast).nil?
    end
    end

  2. Scott | August 27, 2008