[英]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.rb
到spec/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.