Last active
August 12, 2016 15:45
-
-
Save nchelluri/c8b5c565230730800fdac3e9779c810d to your computer and use it in GitHub Desktop.
Mailer Exceptions not showing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Using Rails 5. Why won't my Mailer show exceptions in the log? | |
- ActionMailer Config from development.rb: | |
[...] | |
config.action_mailer.raise_delivery_errors = true | |
config.action_mailer.perform_deliveries = true | |
config.action_mailer.logger = Logger.new($stdout) # this is experimental, doesn't seem to make a difference | |
config.action_mailer.perform_caching = false | |
config.action_mailer.delivery_method = :file | |
[...] | |
- Mailer code: the commented out @url line works fine. The uncommented @url line doesn't, but it doesn't log an exception! Why? | |
class LoginMailer < ApplicationMailer | |
def forgot_password(user) | |
@user = user | |
@url = reset_password_path(@user.password_reset_token) | |
# @url = 'asdf' | |
mail(to: @user.email, subject: t('login.forgot_your_password')) | |
end | |
end | |
- Templates: | |
- ERB: | |
<%= t('login.forgot_your_password') %> | |
<%= t('login.click_here_to_reset_it') %> <%= @url %> | |
- Slim: | |
.container | |
.row | |
.col-sm-12.col-md-4.col-md-offset-4 | |
.pad-top-100 | |
h4.text-center = t('login.forgot_your_password') | |
hr | |
p.text-center = t('login.click_here_to_reset_password_html', url: @url) | |
- Logs with URL Helper: | |
Started POST "/forgot_your_password" for ::1 at 2016-08-12 12:25:18 -0300 | |
Processing by LoginController#do_forgot_your_password as HTML | |
Parameters: {"authenticity_token"=>"I9AX/ABqz9hx8DMBrPv7HgDIiavuVQ6geY/MN3KDCPnrGfCHPMSPn2HTdDknqS/qC3OEDYntlRtD2Fvbk1zyFw==", "email"=>"narsa@inyourhood.ca"} | |
User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'narsa@inyourhood.ca' LIMIT 1 | |
(0.2ms) BEGIN | |
SQL (0.4ms) UPDATE `users` SET `password_reset_token` = '1471015518:7b8b0c39d312b3b5f04fa1f27721053a', `updated_at` = '2016-08-12 15:25:18' WHERE `users`.`id` = 1 | |
(1.4ms) COMMIT | |
[ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: 95d9b5ad-6619-400e-baeb-cca35b0ba0b6) to Async(mailers) with arguments: "LoginMailer", "forgot_password", "deliver_now", #<GlobalID:0x007fae24d088b8 @uri=#<URI::GID gid://locatrix/User/1>> | |
User Load (1.9ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1 | |
[ActiveJob] [ActionMailer::DeliveryJob] [95d9b5ad-6619-400e-baeb-cca35b0ba0b6] Performing ActionMailer::DeliveryJob from Async(mailers) with arguments: "LoginMailer", "forgot_password", "deliver_now", #<GlobalID:0x007fae25478d28 @uri=#<URI::GID gid://locatrix/User/1>> | |
D, [2016-08-12T12:25:18.490484 #87308] DEBUG -- : LoginMailer#forgot_password: processed outbound mail in 14.2ms | |
[ActiveJob] [ActionMailer::DeliveryJob] [95d9b5ad-6619-400e-baeb-cca35b0ba0b6] Performed ActionMailer::DeliveryJob from Async(mailers) in 15.95ms | |
Rendering login/do_forgot_your_password.html.slim within layouts/application | |
Rendered login/do_forgot_your_password.html.slim within layouts/application (5.5ms) | |
Completed 200 OK in 111ms (Views: 41.5ms | ActiveRecord: 7.3ms) | |
- Logs w/o URL Helper: | |
Started POST "/forgot_your_password" for ::1 at 2016-08-12 12:26:10 -0300 | |
Processing by LoginController#do_forgot_your_password as HTML | |
Parameters: {"authenticity_token"=>"4XN/ImBQwLDZHTTNH9RJATHHKQX84ozYpFKYUFfs55UpuphZXP6A98k+c/WUhp31Onwko5taF2OeBQ+8tjMdew==", "email"=>"narsa@inyourhood.ca"} | |
User Load (1.1ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'narsa@inyourhood.ca' LIMIT 1 | |
(0.2ms) BEGIN | |
SQL (0.9ms) UPDATE `users` SET `password_reset_token` = '1471015570:bcf2ea37ab1c7d55f977f701fa2d0dbd', `updated_at` = '2016-08-12 15:26:10' WHERE `users`.`id` = 1 | |
(1.3ms) COMMIT | |
[ActiveJob] Enqueued ActionMailer::DeliveryJob (Job ID: 683622c0-86a3-4cd2-882d-b45091705d5d) to Async(mailers) with arguments: "LoginMailer", "forgot_password", "deliver_now", #<GlobalID:0x007fae256a7b08 @uri=#<URI::GID gid://locatrix/User/1>> | |
User Load (5.5ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1 | |
Rendering login/do_forgot_your_password.html.slim within layouts/application | |
[ActiveJob] [ActionMailer::DeliveryJob] [683622c0-86a3-4cd2-882d-b45091705d5d] Performing ActionMailer::DeliveryJob from Async(mailers) with arguments: "LoginMailer", "forgot_password", "deliver_now", #<GlobalID:0x007fae22bdc608 @uri=#<URI::GID gid://locatrix/User/1>> | |
Rendered login/do_forgot_your_password.html.slim within layouts/application (4.0ms) | |
[ActiveJob] [ActionMailer::DeliveryJob] [683622c0-86a3-4cd2-882d-b45091705d5d] Rendering login_mailer/forgot_password.html.slim within layouts/mailer | |
[ActiveJob] [ActionMailer::DeliveryJob] [683622c0-86a3-4cd2-882d-b45091705d5d] Rendered login_mailer/forgot_password.html.slim within layouts/mailer (4.3ms) | |
Completed 200 OK in 116ms (Views: 75.2ms | ActiveRecord: 4.8ms) | |
D, [2016-08-12T12:26:10.572345 #87308] DEBUG -- : LoginMailer#forgot_password: processed outbound mail in 245.1ms | |
I, [2016-08-12T12:26:10.584968 #87308] INFO -- : Sent mail to narsa@inyourhood.ca (12.3ms) | |
D, [2016-08-12T12:26:10.585044 #87308] DEBUG -- : Date: Fri, 12 Aug 2016 12:26:10 -0300 | |
From: support@inyourhood.ca | |
To: narsa@inyourhood.ca | |
Message-ID: <57adea928d146_1550c3fd710623c8052595@Narsimhams-MacBook.local.mail> | |
Subject: Forgot your password? | |
Mime-Version: 1.0 | |
Content-Type: text/html; | |
charset=UTF-8 | |
Content-Transfer-Encoding: 7bit | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<style> | |
/* Email styles need to be inline */ | |
</style> | |
</head> | |
<body> | |
<div class="container"><div class="row"><div class="col-sm-12 col-md-4 col-md-offset-4"><div class="pad-top-100"></div><h4 class="text-center">Forgot your password?</h4><hr /><p class="text-center">Click <a href="asdf">here</a> to reset your password.</p></div></div></div> | |
</body> | |
</html> | |
[ActiveJob] [ActionMailer::DeliveryJob] [683622c0-86a3-4cd2-882d-b45091705d5d] Performed ActionMailer::DeliveryJob from Async(mailers) in 258.62ms | |
def forgot_password(user)
puts "\n\n\nHELLO"
@user = user
# @url = reset_password_path(@user.password_reset_token)
puts "\n\n\n"
puts "@url: #{@url}\n\n\n\n"
@url = 'asdf'
mail(to: @user.email, subject: t('login.forgot_your_password'))
end
get '/forgot_your_password/:token', to: 'login#reset_password', as: 'reset_password'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The helper
reset_password_path
works in Rails console.