Hi I have to access the current user into my action mailer, but I getting following error
undefined local variable or method `current_user' for #<WelcomeMailer:0xa9e6b230>
by using this link I am using application helper for getting the current user. Here is my WelcomeMailer
class WelcomeMailer < ActionMailer::Base
layout 'mail_layout'
def send_welcome_email
usr = find_current_logged_in_user
Rails.logger.info("GET_CURRENT_USER_FROM_Helper-->#{usr}")
end
end
and my application helper is as follows
def find_current_logged_in_user
#@current_user ||= User.find_by_remember_token(cookies[:remember_token])
# @current_user ||= session[:current_user_id] && User.find_by_id(session[:current_user_id])
Rails.logger.info("current_user---> #{current_user}")
current_user
end
Also I tried with session and cookies. So how can I resolve this error or is there any other method for accessing current user in action mailer.
I am using Rails 3.2.14 and ruby ruby 2.1.0