Rails 4.1 Mailer Previews and Devise custom emails

后端 未结 4 1262
星月不相逢
星月不相逢 2020-12-29 19:43

I have a brand new Rails 4.1.1 app where I\'m customizing the Devise emails. I want to have them displayed on the new Rails email preview feature so I did the following:

4条回答
  •  难免孤独
    2020-12-29 20:12

    For those looking to preview Devise emails without using custom mailers, (but still custom emails) this is what I did:

    1. Configure your app for email previewing.

    2. Set up the Devise Mailer Preview class

      a. Rails ~> 4.1

      # mailer/previews/devise_mailer_preview.rb
      class Devise::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
      

      b. Rails ~> 5.0

      class DeviseMailerPreview < ActionMailer::Preview
      
        ... # same setup as Rails 4 above
      
    3. Restart the server

提交回复
热议问题