heartcombo/mail_form

MailForm Instance does not respond to create

activestylus opened this issue · 3 comments

I will let the console speak for itself:

c = ContactMailer.new(:name => 'n', :email => '4', :message => 'e' )
=> #<ContactMailer:0x10318f570 @name="n", @email="4", @message="e">

c.create
NoMethodError: undefined method `create' for #<ContactMailer:0x10318f570 @name="n", @email="4", @message="e">
from (irb):2

Here is app/mailers/contact_mailer.rb:

class ContactMailer < MailForm::Base
  attributes :name,    :validate => true
  attributes :email,   :validate => /[^@]+@[^\.]+\.[\w\.\-]+/
  attributes :message, :validate => true

  def headers
    {
      :subject => "Contact From Us",
      :to => "me@mysite.com",
      :from => %("#{name}" <#{email}>)
    }
  end
end

I should clarify that I have disabled ActiveRecord and am using Mongoid as my ORM.
Just tested this out with ActiveRecord on a fresh application and it worked just fine.

After further poking in the console it appears that Mongoid does not provide create method for new model instances

Model.new().create will always throw undefined method with this particular ORM

Not sure how Mongoid integration should work but I believe you must set the delivery callback on your own! Take a look at the source code, it is quite small and simple! :)

Improvements to the README are welcome also!

I ended up just hacking it manually using plain old Action Mailer and a tableless model.

Will be sure to give this another stab on the next mailer I have to write.

Nice work overall though - I wish that this was merged into the mail gem