Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Tableless < 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
- # Override the save method to prevent exceptions.
- def save(validate = true)
- validate ? valid? : true
- end
- end
- class Foo < Tableless
- column :bar, :string
- validates_presence_of :bar
- end
- Loading development environment (Rails 2.2.2)
- >> foo = Foo.new
- => #<Foo bar: nil>
- >> foo.valid?
- => false
- >> foo.errors
- => #<ActiveRecord::Errors:0x235b270 @errors={"bar"=>["can't be blank"]}, @base=#<Foo bar: nil>>
- class Car
- # here goes all your model's stuff
- end
- class Car
- attr_accessor :wheels # this will create for you the reader and writer for this attribute
- attr_accessor :doors # ya, this will do the same
- # here goes all your model's stuff
- end
- class Car < ActiveRecord::Base
- self.abstract = true
- end
- my_car = Car.new
- config.frameworks -= [:active_record]
Add Comment
Please, Sign In to add comment