9

我正在学习使用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"
4

2 回答 2

12

注册确认.html.rb ? 查看文件应以 erb 结尾。

将您的视图文件名重命名为:

registration_confirmation.html.erb # HTML format
registration_confirmation.text.erb # Plain text format
于 2013-08-21T23:56:59.103 回答
2

看起来问题是文件扩展名,而erb不是rb.

于 2013-08-21T23:54:04.163 回答