Ad

Rails ContactForm With Non ActiveRecord Model - Validations

Can anyone share a few guides, tips or links to what constitute best practices for creating a model that represents a contact form which is not backed up by a table in the database, but can still validate the data entered?

Thanks.

EDIT: I forgot to mention, that if it is a gem or a plug-in, it should work with Ruby 1.9.1 on Rails 2.3.2.

This - stackoverflow.com/questions/315850/rails-model-without-database doesn't really cut it, as it is a pretty old and not maintained and neither does this - stackoverflow.com/questions/937429/activerecordbase-without-table-rails as it is pretty incomplete.

Ad

Answer

Check out the validatable gem.

class Person
  include Validatable
  validates_presence_of :name
  attr_accessor :name
end

See: http://validatable.rubyforge.org/

See: http://rorblog.techcfl.com/2008/04/02/custom-form-validations-without-activerecord/

This has also been asked several times on StackOverflow:

Rails model without database

ActiveRecord::Base Without Table

Ad
source: stackoverflow.com
Ad