9
votes

I'm learning to send e-mails with Railscast #206. The tutorial uses Rails 3 but I'm using Rails 4 .

app/mailers/user_mailer.rb:
class UserMailer < ActionMailer::Base
    default from: "[email protected]"

    def registration_confirmation(user)
        @user = user
        mail(:to => "#{user.name}", :subject => "Registered")
    end
end

app/views/user_mailer/registration_confirmation.text.rb:

<%= @user.name %>,

Thank you for registering!

Edit profile: <%= edit_user_url(@user) %>

app/views/user_mailer/registration_confirmation.html.rb :

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

<p>Thank you for registering!</p>

<p><%= link_to "Edit profile", edit_user_url(@user) %></p>

app/controllers/users_controller.rb:

class UsersController < ApplicationController
  ......
  def create
    @user = User.new(user_params)
    if @user.save 
      sign_in @user
      flash[:success] = "Welcome"
      UserMailer.registration_confirmation(@user).deliver
      redirect_to @user
    else
      render 'new'
    end
  end
 ......
end

when user signup, he should received an email in theory, but it turns out:

Template is missing

Missing template user_mailer/registration_confirmation with "mailer". Searched in: * "user_mailer"
2

2 Answers

12
votes

registration_confirmation.html.rb ? View files should end with an erb.

Rename your view file names to:

registration_confirmation.html.erb # HTML format
registration_confirmation.text.erb # Plain text format
2
votes

Looks like the problem is the file extension, is erb not rb.