在我的ROR应用程序,我想发送确认电子邮件到我的注册用户,当他们注册,我的网站是在本地主机上当前。 我得到这个错误:
"undefined method `recipients' for #<UserMailer:0x3d841a0>"
这里是我的代码;
development.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { :host => "localhost:3000"}
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:authentication => :login,
:user_name => "myemailid@gmail.com",
:password => "myrealpassword"
}
Users_controller.rb
def new
UserMailer.registration_confirmation(@user).deliver
end
def create
@user = User.new(params[:user])
if @user.save
UserMailer.registration_confirmation(@user).deliver
sign_in @user
flash[:success] = "Welcome!"
redirect_to @user
else
render 'new'
end
end
user_mailer.rb
class UserMailer < ActionMailer::Base
def registration_confirmation(user)
recipients user.email
from "myemailid@gmail.com"
subject "Thank you for registration"
body :user => user
end
end
** ** development.rb
config.action_mailer.delivery_method = :sendmail
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
** ** Users_controller.rb
def new
UserMailer.registration_confirmation(@user).deliver
end
def create
@user = User.new(params[:user])
if @user.save
UserMailer.registration_confirmation(@user).deliver
sign_in @user
flash[:success] = "Welcome!"
redirect_to @user
else
render 'new'
end
end
** ** User_mailer.rb
def registration_confirmation(user)
@message = 'whatever you want to say here!'
mail(:from => "myemailid@gmail.com", :to => user.email, :subject => "Thank you for registration")
end
** /应用/视图/ user_mailer文件/ registration_confirmation.text.erb *
<%= @message %>
这就是我在发展模式所做的,和它的作品
您正在使用什么版本的Rails的?
电子邮件发送3.2版本改变(我相信)
http://api.rubyonrails.org/classes/ActionMailer/Base.html
尝试:
UserMailer.registration_confirmation(@user).deliver
这是你的user_mailer.rb
user_mailer.rb
class UserMailer < ActionMailer::Base
def registration_confirmation(user)
recipients user.email
from "myemailid@gmail.com"
subject "Thank you for registration"
body :user => user
end
尝试改为:
class UserMailer < ActionMailer::Base
default from: "myemailid@gmail.com"
def registration_confirmation(user)
mail(to: user.email, subject: "Thank you for registration")
end
end
并成立了意见/ user_mailer文件如registration_confirmation.html.erb相应的视图