0

I'm upgrading rails 2.3.2 app ot rails 3. Have unknown error with sending email message in MailerFormError. MailerFormError is my model: class MailerFormError < ActionMailer::Base

At 1st I have error with 'deliver_send' method (undefined method `deliver_sent' for MailerFormError:Class), I change it to 'send'. Now I have this:



   NoMethodError in LeadsController#create
   undefined method `part' for #

My code in controller:



    @msg = {}
    @msg["errors"] = @lead.errors
    @msg["params"] = params
    #MailerFormError.deliver_sent(@msg)
    MailerFormError.sent(@msg)

This is my class with sending method:



      def sent(msg, sent_at = Time.now)
        @subject    = ("Ошибка при заполнении формы").force_encoding('iso-8859-1').encode('utf-8')
        @recipients = 'mymail@gmail.com'
        @from       = 'mymail@gmail.com'
        @sent_on    = sent_at
        @headers    = {}

        part( :content_type => "multipart/alternative" ) do |p|
          p.part :content_type => "text/plain", 
                 :body => render_message("sent.plain.erb", :msg=>msg )
        end

      end
Community
  • 1
  • 1
bmalets
  • 3,207
  • 7
  • 35
  • 64

1 Answers1

0

1) for Rails 3, to send your notification in your controller , you have to write this :

MailerFormError.sent(@msg).deliver

2) And you have to rewrite your 'sent' method in the Rails 3 way :

def sent(msg, sent_at = Time.now)
  ...
  mail(:to => '...', :from => '...', :subject => '...') do |format|
    format.html
    format.text
  end
  ...
end

You can also create the text version and html in your view directory app/views/mail_form_error : sent.text.erb and sent.html.erb

Jean-Marc Delafont
  • 534
  • 1
  • 5
  • 6