Form validation and processing w/o model (no Db/ActiveRecord)

All -
Trying not to fight rails on this, basically have a form and all the same as would be with an ActiveRecord model except that there is no table. I started out using this article:

http://stackoverflow.com/questions/315850/rails-model-without-database

…which is kind of a hack by inheriting ActiveRecord in to non-AR model but am running into some problems and just have the feeling that I am fighting rails and going to spend more time on this than the benefit warrants.

All am looking to do is receive and validate form input, and ideally have the luxuries like Class.new(params[:object]), Class.update_attributes(params[:object]), and for the form to do similar highlighting and error feedback messages as AR.

I found this plug-in: active_form (http://github.com/nesquena/active_form). Wondering if anyone has used or has better ideas.

David

Here is what I do:

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
end

Class Contact < Tableless
  column :address, :string
  column :message, :text

  validates_presence_of :message, :address
end

It works perfectly in Rails 2.3.8, it might break in Rails 3 I haven't
tested yet.

Here is what I do:

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

end

Class Contact < Tableless

column :address, :string

column :message, :text

validates_presence_of :message, :address

end

It works perfectly in Rails 2.3.8, it might break in Rails 3 I haven’t

tested yet.

Thanks Fernando. That is exactly what I was doing (but getting an error) but your telling me it works perfectly for you made me look further and I found an error in a field name that I was validating — so now all works well. Good to have confirmation that this structure is being used successfully by others.

David