Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #1727 (closed enhancement: fixed)

Opened 3 years ago

Last modified 3 years ago

[PATCH] Move assignment of @template in ActionMailer::Base

Reported by: orderthruchaos@gmail.com Assigned to: David
Priority: normal Milestone:
Component: ActionMailer Version: 0.13.1
Severity: normal Keywords: ActionMailer Base @template
Cc:

Description

I'm currently using the Localization generator as a part of the Salted Hash Login Generator. As has been noted in the page

http://wiki.rubyonrails.com/rails/show/SaltedHashLoginGenerator

This module appears to have broken. I've come up with a different solution than noted there. If the ActionMailer::Base class would assign @template in the constructor, instead of in the create! method (in the manner done in the patch), then one could override the naming conventions used by action mailer as follows:

Module Localization

  CONFIG = {
            :default_language => 'en'
           }

  class Mailer < ActionMailer::Base

    def initialize( method_name, *parameters )
      @template = method_name + "_#{CONFIG[:default_language]}"
      super
    end

  end

end

To using the custom naming conventions, I would simply replace inheritance from ActionMailer::Base with Localization::Mailer.

Unfortunately, I don't see an "upload file" link on this form. I will attempt to attach the file after posting this message, but in case I cannot get it to work, here is the patch:

Index: base.rb
===================================================================
--- base.rb     (revision 1816)
+++ base.rb     (working copy)
@@ -165,6 +165,7 @@
     # remain uninitialized (useful when you only need to invoke the "receive"
     # method, for instance).
     def initialize(method_name=nil, *parameters) #:nodoc:
+      @template = method_name if @template.nil?
       create!(method_name, *parameters) if method_name 
     end
 
@@ -175,7 +176,6 @@
       @charset = @@default_charset.dup
       @content_type = @@default_content_type.dup
       @implicit_parts_order = @@default_implicit_parts_order.dup
-      @template = method_name
       @parts = []
       @headers = {}
       @body = {}

I have tested this patch using customized tests, and the original test suite, on linux with success for all tests.

Thanks, Brett

Attachments

actionmailer_move_ATtemplate_patch.diff (0.7 kB) - added by orderthruchaos@gmail.com on 07/13/05 08:25:22.
Patch for this ticket.

Change History

07/13/05 08:25:22 changed by orderthruchaos@gmail.com

  • attachment actionmailer_move_ATtemplate_patch.diff added.

Patch for this ticket.

07/19/05 10:47:17 changed by orderthruchaos _at_ gmail _dot_ com

  • severity changed from normal to enhancement.

See also:

[Salted Hash Login Generator http://wiki.rubyonrails.com/rails/show/SaltedHashLoginGenerator]

07/19/05 12:10:04 changed by orderthruchaos _at_ gmail _dot_ com

One more thing... could you please remove my email address from this page? I can't do so, and my spam levels have increased since posting it.

08/22/05 20:55:31 changed by minam

  • status changed from new to closed.
  • resolution set to fixed.

Just committed [2035]. This provides a different solution than what you proposed, but I think it will ultimately prove more flexible. To do what you want, you just need to override the initialize_defaults method, call super, and then change any of the defaults to your own values:

}}} Module Localization

CONFIG = {

:default_language => 'en'

}

class Mailer < ActionMailer::Base

def initialize_defaults(method_name)

super @template << "_#{CONFIG[:default_language]}"

end

end

end }}}