简体   繁体   English

预览 devise 邮件未找到

[英]Preview devise mailer not found

I try to have a preview of devise mailer but when it doesn't work.我尝试预览 devise 邮件程序,但是当它不起作用时。

I have followed this rails guide and it doesn't seems difficult and many things to do.我已经遵循了这个rails guide ,它似乎并不困难并且有很多事情要做。

Devise already have a mailer class here Devise 已经有一个邮件 class 这里

So I should only have to create a preview file so here is what I have done so far.所以我只需要创建一个预览文件,这就是我到目前为止所做的。

I generated my devise views in the repository app/views/users/mailer/我在存储库app/views/users/mailer/中生成了我的 devise 视图

I have my devise.rb which look like that我有我的devise.rb看起来像这样

Devise.setup do |config|
# ==> Mailer Configuration
  # Configure the e-mail address which will be shown in Devise::Mailer,
  # note that it will be overwritten if you use your own mailer class
  # with default "from" parameter.
  config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'

  # Configure the class responsible to send e-mails.
  config.mailer = 'Devise::Mailer'
  # Configure the parent class responsible to send e-mails.
  #config.parent_mailer = 'ActionMailer::Base'
end

I have my test/mailers/previews/devise_mailer_preview.rb我有我的test/mailers/previews/devise_mailer_preview.rb

class DeviseMailerPreview< ActionMailer::Preview

  def confirmation_instructions
    Devise::Mailer.confirmation_instructions(User.first, "faketoken")
  end

  def reset_password_instructions
    Devise::Mailer.reset_password_instructions(User.first, "faketoken")
  end

end

I didn't change the path config.action_mailer.preview_path in my application.rb because test/mailers/previews is the default path我没有更改application.rb中的路径config.action_mailer.preview_path因为test/mailers/previews是默认路径

So now when I try to access to http://localhost:3000/rails/mailers I have a white empty page and if I try http://localhost:3000/rails/mailers/users/mailer/confirmation_instructions I have this error Mailer preview 'users/mailer/confirmation_instructions' not found所以现在当我尝试访问http://localhost:3000/rails/mailers我有一个白色的空白页面,如果我尝试http://localhost:3000/rails/mailers/users/mailer/confirmation_instructions我有这个错误Mailer preview 'users/mailer/confirmation_instructions' not found

I tried many different link but still have the same error, I also tried to followed this stackoverflow answer but no success.我尝试了许多不同的链接但仍然有相同的错误,我也尝试遵循这个stackoverflow 答案但没有成功。

It's seems so easy but I can't succeed...这似乎很容易,但我无法成功......

Ok I found out why.好的,我发现了原因。

Because I'm using the gem rspec-rails the repository test is replaced tp spec I just needed to move my test/mailers/previews/devise/mailer_preview.rb to spec/mailers/previews/devise/mailer_preview.rb and still not need to change the configuration of config/application.rb因为我使用的是 gem rspec-rails存储库test被替换 tp spec我只需要将我的test/mailers/previews/devise/mailer_preview.rbspec/mailers/previews/devise/mailer_preview.rb并且仍然不需要更改config/application.rb的配置

Hope it will help some people希望它会帮助一些人

also note that in rails 6 your devise mailer preview should be wrote with a module另请注意,在 rails 6 中,您的 devise 邮件预览应使用模块编写

module Devise
class MailerPreview< ActionMailer::Preview

  def confirmation_instructions
    Devise::Mailer.confirmation_instructions(User.first, "faketoken")
  end

  def reset_password_instructions
    Devise::Mailer.reset_password_instructions(User.first, "faketoken")
  end

end
end

Given config.mailer = 'Devise::Mailer' ...给定config.mailer = 'Devise::Mailer' ...

Your mailer preview should be found in the test/mailers/previews/devise directory.您的邮件预览应该在test/mailers/previews/devise目录中找到。

So, you can create a mailer_preview.rb file in that directory (not users directory)...因此,您可以在该目录(不是用户目录)中创建一个mailer_preview.rb文件...

$ mkdir test/mailers/previews/devise
$ touch test/mailers/previews/devise/mailer_preview.rb

Then your class name for mailer_preview.rb should be Devise::MailerPreview < ActionMailer::Preview那么您的 mailer_preview.rb 的mailer_preview.rb名称应该是Devise::MailerPreview < ActionMailer::Preview

Moving the mailers folder worked for me!移动邮件文件夹对我有用!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM