前提・実現したいこと
railsの初学者で質問内容に不備があれば申し訳ありません。
現在railsでアプリケーションを作成しており、その中でユーザーがパスワードを忘れてしまった時に、パスワードの再設定リンクが載っているメールをユーザーに送信し、そのリンクで新しいパスワードを設定するという機能を付けようとしています。
その機能を実装するに当たって、まずはメールのプレビューが表示されるかを確認しようと思い、rails tutorialを参考に環境の設定を行なった後
「http://localhost:3000/rails/mailers/user_mailer/password_reset」
にアクセスしたところ、以下のエラーが発生しております。
発生している問題・エラーメッセージ
Unknown action Mailer preview 'user_mailer/password_reset' not found
該当のソースコード
config/environments/development.rb
. . . config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :test host = 'localhost:3000' config.action_mailer.default_url_options = { host: host, protocol: 'http' } config.action_mailer.perform_caching = false . . .
app/views/user_mailer/password_reset.html.erb
<h1>User#password_reset</h1> <p> <%= @greeting %>, find me in app/views/user_mailer/password_reset.html.erb </p>
app/mailers/user_mailer.rb
class UserMailer < ApplicationMailer # Subject can be set in your I18n file at config/locales/en.yml # with the following lookup: # # en.user_mailer.password_reset.subject # def password_reset @greeting = "Hi" mail to: "to@example.org" end end
spec/mailers/previews/user_mailer_preview.rb
# Preview all emails at http://localhost:3000/rails/mailers/user_mailer class UserMailerPreview < ActionMailer::Preview # Preview this email at http://localhost:3000/rails/mailers/user_mailer/password_reset def password_reset UserMailer.password_reset end end
試したこと
・エラーにてuser_mailer/password_resetが見つからないとのことですが、viewにuser_mailer/password_resetがあることは確認しております。
・テストにRSpecを使用しており、previewのデフォルトの参照先が、specディレクトリになっていない可能性があるとの記事を見つけたため、config/environments/development.rbに
config.action_mailer.preview_path = "#{Rails.root}/spec/mailers/previews"
を追記しましたがダメでした。
・gemでrspec-railsがtest環境にしか入っていないことが問題ではと考え、
group :development, :test do ・ ・ ・ gem 'rspec-rails' end
を追加しましたがエラーでした。
ご教授いただければ幸いです。
何卒よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。