ActiveRecord time and datetime


Suppose I have a model class which has a time field:

class CreateAppointments < ActiveRecord::Migration
  def change
    create_table :appointments do |t|
      t.string :name
      t.datetime :startTime
      t.datetime :endTime
      t.string :description


When I test drive it in rails console, I can input any value int he
startTime and endTime such as:

a =
a.startTime = 1234
a.endTime = 5678

My question is does Rails support some basic data type validation for us
so that we can always input a correct format?


The way to do it is to always go via a Time object. If the user is
entering data then parse that into a Time object then save that. If
you need to check that the time is in a particular range for example
then also include a validation in the model.