eltiare (owner)

Revisions

gist: 50106 Download_button fork
public
Public Clone URL: git://gist.github.com/50106.git
Ruby
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
class MessageMailer < Merb::MailController
  include DataMapper::Validate
  extend DataMapper::Validate::ClassMethods
  
  def attribute_get(sym); @params[sym] end
  def attribute_set(sym, val); @params[sym] = val end
  
  [:from].each { |s|
    class_eval "
def #{s}; attribute_get(:#{s}) end
def #{s}=(val); attribute_set(:#{s}, val) end
"
  }
  
  validates_format :from, :as => :email_address
  
  def contact_form
    # use params[] passed to this controller to get data
    # read more at http://wiki.merbivore.com/pages/mailers
    render_mail
  end
  
end
 
 
#irb(main):011:0> m = MessageMailer.new(:to => 'asdf@asdf.com', :from => 'asdf@asdf.com', :subject => 'asdf')
#=> #<MessageMailer:0x286782c @params={:from=>"asdf@asdf.com", :subject=>"asdf", :to=>"asdf@asdf.com"}, @_caught_content={}, @_benchmarks={}, @base_controller=nil>
#irb(main):012:0> m.valid?
#=> true
#irb(main):013:0> m.errors
#=> #<DataMapper::Validate::ValidationErrors:0x2877830 @errors={}>