LoginSignup
14
12

More than 5 years have passed since last update.

Rails 4.1.0.rc1でdeviseのメールをプレビューする

Posted at

Rails 4.1からメールのプレビューが出来るようになります。

認証にDeviseを使っている場合も簡単にプレビューできました。

1. メールプレビュー用のディレクトリを準備する

RSpecを使っていてtestディレクトリが無い場合は以下のようにメールプレビュー用のディレクトリを作成します。

% mkdir -p test/mailers/previews/

2. Devise用のプレビュークラスを作成する

メールプレビュー用のディレクトリにDevise用のプレビュークラスを作成します。クラス名はPreviewで終わる必要がありますが、その他はクラス名やメソッド名に制限や規約は無いようです。

test/mailers/previews/devise_preview.rb
class DevisePreview < ActionMailer::Preview
  def confirmation_instructions
    Devise::Mailer.confirmation_instructions(User.new, Devise.friendly_token[0,20])
  end
end

3. プレビューする

ブラウザで http://localhost:3000/rails/mailers/devise/confirmation_instructions にアクセスしてメールをプレビューします。

14
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
14
12