在Rails 4中缺少带有“邮件程序”的模板user_mailer / registration_confirmation

时间:2013-08-21 23:50:52

标签: ruby-on-rails email

我正在学习发送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"

2 个答案:

答案 0 :(得分:12)

registration_confirmation.html.rb?查看文件应以erb。

结尾

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

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

答案 1 :(得分:2)

问题似乎是文件扩展名,erb不是rb