Validations on non SQL field


#1

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?)


#2

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 << ActiveRecord::ConnectionAdapters::Column.new(name.to_s,
default, sql_type.to_s, null)
end

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

validates_presence_of :name, :email_address
end