ruby-on-rails - 子文件夹中的 Rails 邮件程序和邮件程序 View 不起作用

标签 ruby-on-rails ruby-on-rails-3 actionmailer

我有一个邮件程序,我可以在我的日志中看到它正在发送,但电子邮件正文不包含邮件程序 View 中的任何内容。

这是因为我已经将东西放在子文件夹中并且我已经尝试使用 :template_path在我的 mail功能,但无济于事。

应用程序/邮件/营销/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/... 中有邮件 View ,所以我知道这是可能的,但我不确定如何。

最佳答案

您是否尝试过使用 {:template_path => 'marketing/marketing_mailer, :template_name =>'contact'} 发送邮件?

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

关于ruby-on-rails - 子文件夹中的 Rails 邮件程序和邮件程序 View 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20343882/

相关文章:

ruby-on-rails - 在 Ruby 数组中使用返回枚举器的方法的正确方法是什么?

jquery - ror 中使用 Paperclip 进行多次上传

ruby-on-rails - 使用 ActiveRecord::Relation 对象

ruby-on-rails-3 - 导轨 : radio button selection for nested objects

configuration - ActionMailer 设置在开发和生产之间存在错误差异

ruby-on-rails - 在 Rails 中更大的分组 JSON 响应中指定多个(事件模型)序列化程序?

ruby-on-rails - Ruby on Rails,没有发现 Rakefile 错误

ruby-on-rails-3 - FactoryGirl 序列失败

ruby-on-rails-3 - 将额外的实例变量传递给 devise_invitable 电子邮件模板

ruby - Rails:ParameterFilter::compiled_filter 尝试复制符号