我正在学习发送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
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>
应用程序/控制器/ 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"
答案 0 :(得分:12)
registration_confirmation.html.rb?查看文件应以erb。
结尾将您的视图文件名重命名为:
registration_confirmation.html.erb # HTML format
registration_confirmation.text.erb # Plain text format
答案 1 :(得分:2)
问题似乎是文件扩展名,erb
不是rb
。