【问题标题】:ActionMailer Views with Rails 5 api_only使用 Rails 5 api_only 的 ActionMailer 视图
【发布时间】:2016-02-06 04:06:18
【问题描述】:

我目前正在尝试使用我的 Rails api 服务器设置邮件程序。目前,我收到以下错误:ActionView::MissingTemplate (Missing template user_mailer/welcome_email with "mailer". Searched in: * "user_mailer" ):

目前在views/user_mailer/welcome_email.html.erb有一个视图

我的users_mailer.rb 如下所示:

class UserMailer < ApplicationMailer
  default from: 'xx@xxx.com'

  def welcome_email(user)
    @user = user
    @url  = 'http://0.0.0.0:3000/login'
    mail(to: 'xxx@xxxxx.com', subject: 'Welcome to the site')
  end
end

我的控制器这样调用邮件程序:

def show
   UserMailer.welcome_email(@user).deliver_now
   render json: @user
end

我试过设置 config.api_only = false 没有任何运气。

【问题讨论】:

  • 有人也遇到了和你一样的问题github.com/rails-api/rails-api/issues/23 .. :)
  • 我重启了好几次应用,也停止了好几次spring。
  • 我没有看到任何明显的东西。您可以在 repo 中添加问题。
  • 感谢您为我查看代码。我在 Rails 存储库中发布了一个新问题。
  • 您能否在帖子本身中提供问题链接。这样未来的读者也可以得到帮助。谢谢

标签: ruby-on-rails ruby-on-rails-5


【解决方案1】:

答案在issue:

好的 - 发现错误。您将视图存储在 views/user_mailer/ 中,而不是 app/views/user_mailer/。这应该可以解决问题。

【讨论】:

    【解决方案2】:

    保留:

    views/user_mailer/welcome_email.html.erb
    

    代替:

    app/views/user_mailer/welcome_email.html.erb
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-12
      • 1970-01-01
      • 1970-01-01
      • 2014-05-23
      • 1970-01-01
      • 1970-01-01
      • 2013-02-20
      • 1970-01-01
      相关资源
      最近更新 更多