[Rails-core] Active Record Mod's

Rick Olson technoweenie at gmail.com
Thu Feb 23 04:52:39 GMT 2006


On 2/22/06, Nathaniel S. H. Brown <nshb at inimit.com> wrote:
> I am pretty sure this has been brought up elsewhere, and have heard it
> discussed a few places myself.
>
> I want to know what thoughts surround the concept of having ActiveRecord
> have methods such as
>
> class Model < ActiveRecord::Base
>   column :first_name, :string => 255
>   column :description, :text
>   column :created_on, :datetime
>   column :random_number, :integer
>   column :cost, :float
> end

Here's your plugin in just 6 lines of code.

# init.rb
class << ActiveRecord::Base
  def columns() @columns ||= []; end
  def column(name, sql_type = nil, default = nil, null = true)
    columns << ActiveRecord::ConnectionAdapters::Column.new(name.to_s,
default, sql_type.to_s, null)
  end
end

http://rails.techno-weenie.net/tip/2005/11/19/validate_your_forms_with_a_table_less_model


--
Rick Olson
http://techno-weenie.net


More information about the Rails-core mailing list