Validations on non SQL field


Any way to run validations on fields which aren’t in the SQL?

I know there have been some posts about validations on non persistent
objects. I’m talking about validations on nonpersisted fields of
persisted objects.

In general, it seems to me that the validations code is very useful,
totally outside of persistence. Perhaps it should be taken out and made
a mixin?

(Is there a Rails equivalent of RCR’s?)


Copied from Rails Weenie

class Contact < ActiveRecord::Base
def self.columns() @columns ||= []; end
def self.column(name, sql_type = nil, default = nil, null = true)
columns <<,
default, sql_type.to_s, null)

column :name, :string
column :city, :string
column :state, :string
column :phone, :string
column :email_address, :string

validates_presence_of :name, :email_address