ActionMailer w/o database link (e.g., feedback form)


#1

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!


#2

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-link-(e.g.%2C-feedback-form)-t1624886.html#a4403516
Sent from the RubyOnRails Users forum at Nabble.com.