I want to sign_in my user inside my UserMailer using devise:
Desired behavior:
class UserMailer < ActionMailer::Base
# need to include devise somehow
def show_preview(user)
sign_in(:user, user)
response = RestClient.get 'http://localhost:3000/api/posts.json' #this needs authentication
# email_body = format response ... ...
end
end
Problem: I dont know which parts of devise I need to include in my UserMailer, and how to include them.
I've tried include Devise::Controllers::InternalHelpers (in order to use sign_in), from this link, but it seem to be deprecated.
Why: Because I want to have the same data in my email to the user, as what I show the user on the web app. So, I want to access the same api (ie localhost:3000/api/posts.json, which is what I use for my controlle/view, which requires that the user is authenticated.