2014-12-06 64 views
1

我正在使用我的Rails 4應用程序的設計。Devise Rails&Admin_Mailer

我在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: "[email protected]", from: "[email protected]", 
    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: "[email protected]", subject: "Welcome to Co #{user.first_name}") 
end 

我不知道我是否需要CURRENT_USER更換用戶利用色器件的方法也許在第二個方法中,是否需要在{}和/或「」上使用user.email的變體?我嘗試了幾種不同的變化和組合,但沒有取得任何成功。

謝謝你的幫助。

+0

你能後你得到 – pshoukry 2014-12-06 22:46:25

回答

0
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 

用戶替換 - >自

+0

喜確切的錯誤跟蹤,感謝您的建議。當我嘗試它時,出現以下錯誤:ActionView :: Template :: Error(未定義的局部變量或方法'用戶'爲#<#:0x007f60578287f0>)。日誌在我的回調控制器中引用此行:@ user.send_user_welcome_mail – Mel 2014-12-06 23:08:19

+0

爲什麼您在視圖中使用用戶?它應該是@user。 – pshoukry 2014-12-06 23:14:02

+0

就是這樣 - 謝謝。我很想@ – Mel 2014-12-06 23:17:30