Tableless Model

/ Published in: Ruby
Save to your folder(s)

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.

Copy this code and paste it in your HTML
  1. class ${1:name_of_model} < ActiveRecord::Base
  2. def self.columns() @columns ||= []; end
  3. def self.column(name, sql_type = nil, default = nil, null = true)
  4. columns <<, default, sql_type.to_s, null)
  5. end
  7. #insert the names of the form fields here
  8. column :name, :string
  9. column :city, :string
  10. column :state, :string
  11. column :phone, :string
  12. column :email_address, :string
  14. #standard validations will go here
  15. validates_presence_of :name, :email_address
  16. end


Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.