Actually, you can't and most of all, you shouldn't use this kind of Devise helper on your mailer.
Why ? Well, if you search Devise's code base for the user_signed_in?
helper, you will find it in Devise::Controllers::Helpers
module, as you can see here. This means that it is supposed to be used in a controller context, as it uses method such as request
and warden
that is only available on controllers.
If you must make any decision in your mail view based on whether a user is signed in or not, I would recommend you to pass this information from your controller to your mailer:
Your controller:
class UserController < ApplicationController
def your_action
UserMailer.receipt(user_signed_in?).deliver
#....
end
end
Your mailer:
class UserMailer < ActionMailer::Base
def receipt(signed_in)
@signed_in = singed_in
#....
end
end
Your mailer view:
<% if @signed_in %>
Secret link
<% end %>
I hope it helps !