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:
Missing template user_mailer/registration_confirmation with "mailer". Searched in: * "user_mailer"
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
Looks like the problem is the file extension, is erb
not rb
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With