0
votes

I'm going through the Ruby on Rails tutorial and having trouble getting my UserMailer preview to work.

The error I am getting is that when I go to the server, it says Mailer preview 'user_mailer/account_activation' not found.

I am following the code step by step, but it is not working. Here is what I have.

app/mailers/user_mailer.rb class UserMailer < ApplicationMailer

  def account_activation(user)
    @user = user
    mail to: user.email, subject: "Account activation"
  end

test/mailers/previews/user_mailer_previews

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

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: 'https' }

I have read and reread the code on the site https://www.railstutorial.org/book/account_activation and tried changing things out but had no luck

Thank you in advance!

edit: I actually already have a view, sorry should have included it earlier.

app/views/user_mailer/account_activation.html.erb

<h1>Sample App</h1>

<p>Hi <%= @user.name %>,</p>

<p>
  Welcome to the Sample App! Click on the link below to activate your account:
</p>

<%= link_to "Activate", edit_account_activation_url(@user.activation_token,
                                                    email: @user.email) %>
2

2 Answers

1
votes

What url are you trying to go to? I had this same issue, and it was because I was leaving the "rails" portion of the url out (because I thought that part was specific to the tutorial author's particular development environment (it's not)).

Try going to http://localhost:3000/rails/mailers, which should list links to your previews.

0
votes

You also need to create at least one view template for the mailer under app/views/user_mailer.

At its simplest, this can be a file called account_activation.text.erb containing some static text that will become the body of the email.