Skip to content

Instantly share code, notes, and snippets.

@eltiare
Created January 21, 2009 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save eltiare/50106 to your computer and use it in GitHub Desktop.
Save eltiare/50106 to your computer and use it in GitHub Desktop.
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={}>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment