Posted By

vanne on 12/27/06


Tagged

rails ruby


Versions (?)

Who likes this?

8 people have marked this snippet as a favorite

ryanprel
Firanide
bordalix
bezugen
vali29
tkmr
sergeizen
webstic


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.