We Recommend

Beginning Ruby: From Novice to Professional Beginning Ruby: From Novice to Professional
Beginning Ruby is a thoroughly contemporary guide for every type of reader wanting to learn Ruby, from novice programmers to web developers to Ruby newcomers. It starts by explaining the principles behind object-oriented programming and within a few chapters builds toward creating a genuine Ruby application.


Posted By

vanne on 12/27/06


Tagged

rails ruby


Versions (?)


Who likes this?

6 people have marked this snippet as a favorite

ryanprel
Firanide
bordalix
bezugen
vali29
tkmr


Tableless Model


Published in: Ruby 


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

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/nameofyour_model to use.

  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 << ActiveRecord::ConnectionAdapters::Column.new(name.to_s, default, sql_type.to_s, null)
  5. end
  6.  
  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
  13.  
  14. #standard validations will go here
  15. validates_presence_of :name, :email_address
  16. end

Report this snippet 

You need to login to post a comment.