加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 子文件夹中的Rails邮件程序和邮件程序视图无法

发布时间:2020-12-17 03:55:42 所属栏目:百科 来源:网络整理
导读:我有一个邮件,我可以在我的日志中看到发送,但邮件正文不包含邮件程序视图中的任何内容. 这是因为我把东西放在子文件夹中,我尝试在我的邮件功能中使用:template_path,但无济于事. 应用程序/邮寄/营销/ marketing_mailer.rb class Marketing::MarketingMailer
我有一个邮件,我可以在我的日志中看到发送,但邮件正文不包含邮件程序视图中的任何内容.

这是因为我把东西放在子文件夹中,我尝试在我的邮件功能中使用:template_path,但无济于事.

应用程序/邮寄/营销/ marketing_mailer.rb

class Marketing::MarketingMailer < ActionMailer::Base

    require 'mail'
    address = Mail::Address.new "test@example.com" # ex: "john@example.com"
    address.display_name = "Text" # ex: "John Doe"
    # Set the From or Reply-To header to the following:
    address.format # returns "John Doe <john@example.com>"
    default from: address

    # Sends an email when someone fills out the contact form
    def contact(name,email,message)
        @name = name
        @email = email
        @message = message
        mail(:subject => "Test",:to => 'test@example.com',:reply_to => @email) # <== I've tried using :template_path => 'marketing','marketing/marketing_mailer',etc,but none worked.
    end
end

/app/views/marketing/marketing_mailer/contact.html.erb

<!DOCTYPE html>
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
  </head>
  <body>
    <p>Name: <%= @name %></p>
    <p>Email: <%= @email %></p>
    <p>Message: <%= @message %></p>
  </body>
</html>

我注意到devise在/ views / devise / mailers /中有邮件视图…所以我知道这是可能的,但我不确定如何.

解决方法

您是否尝试使用{:template_path => ‘marketing / marketing_mailer,:template_name =>’contact’}?

模板名称可能以某种方式期望文件名中的命名空间

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读