Return to Snippet

Revision: 2060
at December 27, 2006 08:31 by vanne


Initial Code
class ${1:name_of_model} < 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
      
      #insert the names of the form fields here
      column :name, :string
      column :city, :string
      column :state, :string
      column :phone, :string
      column :email_address, :string
  
      #standard validations will go here
      validates_presence_of :name, :email_address
end

Initial URL
http://www.railsweenie.com/forums/2/topics/724

Initial Description
This is useful for using ActiveRecord validations without the ActiveRecord DB dependencies, this snippet is meant to be used with Textmate... create this in models/name_of_your_model to use.

Initial Title
Tableless Model

Initial Tags
rails, ruby

Initial Language
Ruby