[英]Devise Rails & Admin_Mailer
我在我的Rails 4應用程序中使用了devise。
我的user.rb
模型中包含以下內容:
def send_admin_mail
AdminMailer.new_user_waiting_for_approval(self).deliver
end
def send_user_welcome_mail
AdminMailer.new_user_waiting_for_access(user).deliver
end
當新用戶注冊時,第一種方法會向我發送電子郵件。 目的是第二種方法向新用戶發送歡迎電子郵件。 第一種方法有效。 第二個問題是“ no_method_error”(我的回調控制器中的未定義方法電子郵件)的問題。
我的回調控制器具有以下內容:
def linkedin
@user = User.find_for_linkedin_oauth(request.env["omniauth.auth"])
if @user.persisted?
@user.send_admin_mail
@user.send_user_welcome_mail
redirect_to root_path, :event => :authentication
# sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
# set_flash_message(:notice, :success, :kind => "LinkedIn") if is_navigational_format?
else
session["devise.linkedin_data"] = request.env["omniauth.auth"]
redirect_to root_path
end
end
我的admin_mailer有:
def new_user_waiting_for_approval(user)
@user = user
mail(to: "myemailaddress@gmail.com", from: "myemailaddress@gmail.com",
subject: "Registration Request #{user.first_name} #{user.last_name} <#{user.email}>")
end
def new_user_waiting_for_access(user)
@user = user
mail(to: user.email, from: "myemailaddress@gmail.com", subject: "Welcome to Co #{user.first_name}")
end
我想知道是否需要使用current_user替換用戶以使用devise方法,或者是否需要在user.email的第二種方法中對{}和/或“”進行某些更改? 我嘗試了幾種不同的變體和組合,但沒有取得任何成功。
謝謝您的幫助。
def send_user_welcome_mail
AdminMailer.new_user_waiting_for_access(user).deliver
end
應該替換為
def send_user_welcome_mail
AdminMailer.new_user_waiting_for_access(self).deliver
end
用戶->自我
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.