Ruby on rails 未为邮件程序正确拾取模板
我在一个模块中定义了两个mailer类,如下所示: 1。app/mailers/my_mailers/mailer_a.rbRuby on rails 未为邮件程序正确拾取模板,ruby-on-rails,ruby,ruby-on-rails-3,templates,Ruby On Rails,Ruby,Ruby On Rails 3,Templates,我在一个模块中定义了两个mailer类,如下所示: 1。app/mailers/my_mailers/mailer_a.rb module MyMailers class MailerA < BaseMailer def main mail(:to => 'xyz@abc.com', :subject => 'Mail Subject') end end end module MyMailers class MailerB <
module MyMailers
class MailerA < BaseMailer
def main
mail(:to => 'xyz@abc.com', :subject => 'Mail Subject')
end
end
end
module MyMailers
class MailerB < MailerA
def some_method
end
end
end
class BaseMailer < ActionMailer::Base
...
...
end
问题:
当我尝试调用MailerB的main()方法时,它应该调用MailerA的main()方法(因为MailerB类没有main可用),而MailerB类则通过在app/views/my_modules/mailer_b
目录中搜索main
模板来尝试调用send mail()。但是mailer\u b
视图没有任何main
模板,因此它应该回退到父类视图,即mailer\u a
views目录,并开始呈现main.html.erb
但在我的例子中,收到的邮件总是空的,就好像没有找到模板一样,我认为对模板的搜索只在app/views/mailer_b/
目录中停止,而不是在mailer继承中继续
我也尝试过使用:template_path机制,但结果仍然相同(空邮件)
有谁能为这种情况提出一些修复/解决方案?请让我知道我是否应该提供更多的细节
使用Rails版本:3.2.1x
谢谢为什么您要为邮件程序使用模块。您的代码很好,我看不出您的模板没有相应加载的任何原因。尝试删除模块,然后像这样使用类:-
class MailerA < BaseMailer
default from: "support@mydomain.com"
##if needed
##layout 'mailer_a'
def registration_confirmation(user_email)
//do your stuff with user_email
mail(:to => user_email, :subject =>"Good to see you")
##in case multiple templates in same folder
## mail(:to => user_email, :subject =>"Good to see you", :template_name => "main_2")
end
end##class ends
class-MailerAuser\u email,:subject=>“很高兴见到你”)
##如果同一文件夹中有多个模板
##邮件(:to=>user\u email,:subject=>“很高兴见到你”,:template\u name=>“main\u 2”)
终止
下课
mailer\u a
和mailer\u b
模板被归类为用于某些特定目的的邮件,因此我将它们归入my\u mailer
模块,对于ex:mailer_c,任何新的类似邮件程序都将是同一模块的一部分。我尝试删除模块my_modules
,但rails仍然没有选择合适的模板。
class MailerA < BaseMailer
default from: "support@mydomain.com"
##if needed
##layout 'mailer_a'
def registration_confirmation(user_email)
//do your stuff with user_email
mail(:to => user_email, :subject =>"Good to see you")
##in case multiple templates in same folder
## mail(:to => user_email, :subject =>"Good to see you", :template_name => "main_2")
end
end##class ends