Forum: Ruby on Rails ActionMailer w/o database link (e.g., feedback form)

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
7e391d62a0c52ad1f4130aa140335958?d=identicon&s=25 Dave (Guest)
on 2006-05-16 05:23
Hey,

A total noobieQ. Apologies, still learning.

Could anyone point me to examples of a non-database-driven feedback
form, for instance, a simple e-mail feedback form that takes advantage
of ActionMailer? (How do I carry a POST through to a 'def' w/o a
database connection?)

Thanks!
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2006-05-16 07:30
(Received via mailing list)
Rails Recipe 64, "Validating Non-Active Record Objects," in Chad
Fowler's
"Rails Recipes" offers one solution. Another is to use an in-memory
SQLite
database as shown in the code below. Assuming the ClaimStatus model, you
can
then create a ClaimStatusController, and associated views just as though
you
were using a database.

# model.rb
class ClaimStatus < ActiveRecord::Base
  unless const_defined? :SQLITE_SETUP
    SQLITE_SETUP = true
    #self.establish_connection(:adapter => 'sqlite', :dbfile=>
':memory:')
# use if sqlite3 gem not installed
    self.establish_connection(:adapter => 'sqlite3', :dbfile=>
':memory:')
    conn = self.connection
    conn.create_table(self.table_name,
    :primary_key => self.primary_key) do |t|
      #first section
      t.column :full_name,          :string
      t.column :date_of_loss,       :date
      t.column :claim_number,       :string
      t.column :adjuster_name,      :string
      t.column :contact_method,     :string
      t.column :additional_details, :text
    end
  end

  attr_accessible :full_name
  attr_accessible :date_of_loss
  attr_accessible :claim_number
  attr_accessible :adjuster_name
  attr_accessible :contact_method
  attr_accessible :additional_details

  validates_presence_of :full_name, :date_of_loss

  private
  def validate
    unless attributes_before_type_cast['date_of_loss'] =~
/^(\d+(-|\/)){2}\d{4}/
      errors.add('date_of_loss', 'use the form: mm/dd/yyyy')
    end
  end
end

--
View this message in context:
http://www.nabble.com/ActionMailer-w-o-database-li...
Sent from the RubyOnRails Users forum at Nabble.com.
This topic is locked and can not be replied to.