Forum: Ruby on Rails Validations on non SQL field

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
List R. (Guest)
on 2005-11-29 03:57
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?)
leonleslie (Guest)
on 2005-11-29 16:04
(Received via mailing list)
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
This topic is locked and can not be replied to.