Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Missing template user_mailer/registration_confirmation with "mailer" in Rails 4

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"
like image 962
jsvisa Avatar asked Aug 21 '13 23:08

jsvisa


2 Answers

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
like image 158
Andrew Cetinic Avatar answered Nov 13 '22 11:11

Andrew Cetinic


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

like image 25
cortex Avatar answered Nov 13 '22 10:11

cortex