Railsチュートリアル第11章にてメールプレビューにアクセスできない
コード
config/environments/development.rbファイル Rails.application.configure do config.cache_classes = false config.eager_load = false config.consider_all_requests_local = true if Rails.root.join('tmp/caching-dev.txt').exist? config.action_controller.perform_caching = true config.cache_store = :memory_store config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}" } else config.action_controller.perform_caching = false config.cache_store = :null_store end # Don't care if the mailer can't send. config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :test host = '自分のホスト名' # クラウドIDE config.action_mailer.default_url_options = { host: host, protocol: 'https' } 略 end
app/mailers/application_mailer.rbファイル class ApplicationMailer < ActionMailer::Base default from: "noreply@example.com" layout 'mailer' end
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.account_activation.subject # def account_activation(user) @user = user mail to: user.email, subject: "Account activation" end # 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
test/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/account_activation def account_activation user = User.first user.activation_token = User.new_token UserMailer.account_activation(user) end # Preview this email at http://localhost:3000/rails/mailers/user_mailer/password_reset def password_reset UserMailer.password_reset end end
実行結果
以下URLのプレビューページへアクセスを試みるも、、、
http://自分のホスト名/rails/mailers/user_mailer/account_activation
テストの実行結果
ERROR["test_account_activation", UserMailerTest, 1.4476014219999342] test_account_activation#UserMailerTest (1.45s) ArgumentError: ArgumentError: wrong number of arguments (given 0, expected 1) app/mailers/user_mailer.rb:8:in `account_activation' test/mailers/user_mailer_test.rb:6:in `block in <class:UserMailerTest>' FAIL["test_password_reset", UserMailerTest, 1.459731961999978] test_password_reset#UserMailerTest (1.46s) Expected: ["from@example.com"] Actual: ["noreply@example.com"] test/mailers/user_mailer_test.rb:16:in `block in <class:UserMailerTest>' 43/43: [===============================] 100% Time: 00:00:01, Time: 00:00:01 Finished in 1.46772s 43 tests, 167 assertions, 1 failures, 1 errors, 0 skips
解決法分かる方ご享受願います。
あなたの回答
tips
プレビュー