Created
January 21, 2009 18:46
-
-
Save eltiare/50106 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 => '[email protected]', :from => '[email protected]', :subject => 'asdf') | |
#=> #<MessageMailer:0x286782c @params={:from=>"[email protected]", :subject=>"asdf", :to=>"[email protected]"}, @_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