0
  • rails 4.2.5
  • ruby 2.3

I'm using Devise and sending two emails to users.

  • after signup (welcome with confirmation link)
  • after changing email (with confirmation link)

Both are sent with a custom Devise Mailer:

class UserMailer < Devise::Mailer
    layout 'email'
    helper :application
    include Devise::Controllers::UrlHelpers

    def confirmation_instructions(record, token, options={})
        if record.pending_reconfirmation?
            options[:template_name] = 'confirmation_instructions'
        else
            options[:template_name] = 'welcome_email'
        end
        super
    end
end

I can preview the Devise default emails whitout problem (confirmation_instructions, reset_password_instructions or unlock_instructions). My question is all about a custom email preview (welcome_email with confirmation_url).

How to preview the welcome_email with confirmation_url in my UserMailerPreview? Is it possible or should I change my aprouch?

My preview so far:

class UserMailerPreview < ActionMailer::Preview
    def confirmation_instructions
        UserMailer.confirmation_instructions(User.first, '123456', {})
    end
end
maiconsanson
  • 243
  • 3
  • 16
  • 1
    I don't know if I understood correctly your question, but there's a great gem to preview emails: https://github.com/ryanb/letter_opener – Lucas Moulin Feb 22 '16 at 22:48
  • Check out this question http://stackoverflow.com/questions/23716397/rails-4-1-mailer-previews-and-devise-custom-emails – Milos Blasko Feb 23 '16 at 10:29
  • 1
    @akz92 Actually since Rails 4.2.1 we have a feature to do this without any gem. http://edgeguides.rubyonrails.org/4_1_release_notes.html#action-mailer-previews – maiconsanson Feb 23 '16 at 12:20
  • @miloshes I can preview those Devise default emails normally (confirmation_instructions, reset_password_instructions or unlock_instructions). My question is all about a custom email preview (welcome_email with confirmation_url). – maiconsanson Feb 23 '16 at 12:27

0 Answers0