我正在学习使用Railscast #206发送电子邮件。本教程使用 Rails 3,但我使用的是 Rails 4。
应用程序/邮件程序/user_mailer.rb:class UserMailer < ActionMailer::Base
default from: "ryan@railscast.com"
def registration_confirmation(user)
@user = user
mail(:to => "#{user.name}", :subject => "Registered")
end
end
应用程序/视图/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>
应用程序/控制器/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
当用户注册时,理论上他应该会收到一封电子邮件,但事实证明:
模板丢失
Missing template user_mailer/registration_confirmation with "mailer". Searched in: * "user_mailer"