I'm having a problem where my app is generating links from mailers to www.myurl.herokuapp.com/:8080/someurl - and that's breaking all my links, as they work, but not with the :8080 added. i.e. if I manually remove the /:8080/ it works fine.
For example, the reset password generated url that's emailed is:
https://myurl.herokuapp.com/:8080/users/password/edit?reset_password_token=123token123
However, it works fine in development, it's just production where there's an issue. I've managed to hack it by using static urls for some URLs, but for password reset and long-term health I need to fix it.
I'm using: Ruby 2.3.1 Rails 5.1.4 Heroku PGSQL SendInBlue as a mailer
What i've tried:
In reset_password_instructions.html.erb:
Changing the line from:
<p><%= link_to 'Change my password', edit_password_path(@resource, reset_password_token: @token) %></p>
I've also tried removing the default port from production.rb:
config.action_mailer.default_url_options = { host: 'http://myurl.herokuapp.com/' }
Can anyone advise what might be causing this or how to fix it?
Error message:
The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.
If you are the application owner check the logs for more information.
Logs don't seem to throw anything new when clicking on the link in the email, in fact they don't generate anything (?), the last thing in the logs:
2018-09-25T21:16:06.581471+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2018-09-25T21:16:06.709308+00:00 heroku[web.1]: Process exited with status 143
2018-09-25T21:27:39.622506+00:00 heroku[router]: at=info method=GET path="/szallodak/4909;;;" host=staging.herokuapp.com request_id=0eb96201-d562-46d2-93aa-759324d0c64d fwd="95.216.157.196" dyno=web.1 connect=0ms service=6ms status=301 bytes=170 protocol=http
2018-09-25T21:27:41.361516+00:00 heroku[router]: at=info method=GET path="/szallodak/4909" host=staging.herokuapp.com request_id=cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677 fwd="95.216.157.196" dyno=web.1 connect=0ms service=132ms status=404 bytes=1966 protocol=https
2018-09-25T21:27:41.227565+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] Started GET "/szallodak/4909" for 95.216.157.196 at 2018-09-25 21:27:41 +0000
2018-09-25T21:27:41.355281+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677]
2018-09-25T21:27:41.355383+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] ActionController::RoutingError (No route matches [GET] "/szallodak/4909"):
2018-09-25T21:27:41.355437+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677]
2018-09-25T21:27:41.355533+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/show_exceptions.rb:31:in `call'
2018-09-25T21:27:41.355535+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/rack/logger.rb:36:in `call_app'
2018-09-25T21:27:41.355530+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/debug_exceptions.rb:63:in `call'
2018-09-25T21:27:41.355537+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/rack/logger.rb:24:in `block in call'
2018-09-25T21:27:41.355539+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/tagged_logging.rb:69:in `block in tagged'
2018-09-25T21:27:41.355540+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/tagged_logging.rb:26:in `tagged'
2018-09-25T21:27:41.355542+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/tagged_logging.rb:69:in `tagged'
2018-09-25T21:27:41.355544+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/rack/logger.rb:24:in `call'
2018-09-25T21:27:41.355545+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/remote_ip.rb:79:in `call'
2018-09-25T21:27:41.355547+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/request_id.rb:25:in `call'
2018-09-25T21:27:41.355548+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/method_override.rb:22:in `call'
2018-09-25T21:27:41.355550+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/runtime.rb:22:in `call'
2018-09-25T21:27:41.355552+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/activesupport-5.1.6/lib/active_support/cache/strategy/local_cache_middleware.rb:27:in `call'
2018-09-25T21:27:41.355554+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/executor.rb:12:in `call'
2018-09-25T21:27:41.355555+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/static.rb:125:in `call'
2018-09-25T21:27:41.355557+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/rack-2.0.5/lib/rack/sendfile.rb:111:in `call'
2018-09-25T21:27:41.355558+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/actionpack-5.1.6/lib/action_dispatch/middleware/ssl.rb:68:in `call'
2018-09-25T21:27:41.355560+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/railties-5.1.6/lib/rails/engine.rb:522:in `call'
2018-09-25T21:27:41.355561+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/puma-3.12.0/lib/puma/configuration.rb:225:in `call'
2018-09-25T21:27:41.355563+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:658:in `handle_request'
2018-09-25T21:27:41.355564+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:472:in `process_client'
2018-09-25T21:27:41.355566+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/puma-3.12.0/lib/puma/server.rb:332:in `block in run'
2018-09-25T21:27:41.355568+00:00 app[web.1]: [cdc1c6e4-ce66-404c-a4a7-ed8a7c7eb677] vendor/bundle/ruby/2.4.0/gems/puma-3.12.0/lib/puma/thread_pool.rb:133:in `block in spawn_thread'
2018-09-25T21:27:41.657427+00:00 heroku[router]: at=info method=GET path="/szallodak/4909;;;" host=staging.herokuapp.com request_id=47227af4-6a27-4265-8f9f-357d89889a92 fwd="95.216.157.196" dyno=web.1 connect=0ms service=3ms status=301 bytes=170 protocol=http
Very easy fix for anyone else with the same issue, in production.rb I simply added: ",protocol: 'https'" so it now reads:
config.action_mailer.default_url_options = { host: 'http://myapp.herokuapp.com',
protocol: 'https' }
If your protocol isn't https, then you'd simply use http://
I also reverted (though I didn't test it using path) the path, both should work:
<p><%= link_to 'Change my password', edit_password_path(@resource, reset_password_token: @token) %></p>
to
<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>