Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting ArgumentError (Nil location provided. Can't build URI.) after submitting password reset form on development #5468

Closed
zaidhuda opened this issue Feb 10, 2022 · 3 comments · Fixed by #5548

Comments

@zaidhuda
Copy link

Environment

  • Ruby [3.0.3-p157]
  • Rails [7.0.1]
  • Devise [4.8.1]

Current behavior

Submitting the password reset form will show Rails error page. Refreshing the page will render the password reset form. I'm using Mailtrap and the password reset email is being sent correctly. The password reset link also works as expected.

=> Booting Puma
=> Rails 7.0.1 application starting in development 
=> Run `bin/rails server --help` for more startup options
Puma starting in single mode...
* Puma version: 5.6.1 (ruby 3.0.3-p157) ("Birdie's Version")
*  Min threads: 5
*  Max threads: 5
*  Environment: development
*          PID: 21837
* Listening on http://127.0.0.1:3000
* Listening on http://[::1]:3000
Use Ctrl-C to stop
Started POST "/administrators/password" for ::1 at 2022-02-10 21:10:27 +0800
  ActiveRecord::SchemaMigration Pluck (0.5ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Processing by Devise::PasswordsController#create as TURBO_STREAM
  Parameters: {"authenticity_token"=>"[FILTERED]", "administrator"=>{"email"=>"admin@example.com"}, "commit"=>"Send me reset password instructions"}
  Administrator Load (0.5ms)  SELECT "administrators".* FROM "administrators" WHERE "administrators"."email" = $1 ORDER BY "administrators"."id" ASC LIMIT $2  [["email", "admin@example.com"], ["LIMIT", 1]]
  Administrator Load (0.5ms)  SELECT "administrators".* FROM "administrators" WHERE "administrators"."reset_password_token" = $1 ORDER BY "administrators"."id" ASC LIMIT $2  [["reset_password_token", "[FILTERED]"], ["LIMIT", 1]]
  TRANSACTION (0.4ms)  BEGIN
  Administrator Update (0.6ms)  UPDATE "administrators" SET "reset_password_token" = $1, "reset_password_sent_at" = $2, "updated_at" = $3 WHERE "administrators"."id" = $4  [["reset_password_token", "[FILTERED]"], ["reset_password_sent_at", "[FILTERED]"], ["updated_at", "2022-02-10 13:10:27.400453"], ["id", 1]]
  TRANSACTION (0.9ms)  COMMIT
  Rendering /home/zaid/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/devise-4.8.1/app/views/devise/mailer/reset_password_instructions.html.erb
  Rendered /home/zaid/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/devise-4.8.1/app/views/devise/mailer/reset_password_instructions.html.erb (Duration: 1.3ms | Allocations: 1514)
Devise::Mailer#reset_password_instructions: processed outbound mail in 151.2ms
Delivered mail 62050ec38e462_554d116e816711@PC.mail (10829.0ms)
Date: Thu, 10 Feb 2022 21:10:27 +0800
From: noreply@example.com
Reply-To: noreply@example.com
To: admin@example.com
Message-ID: <62050ec38e462_554d116e816711@PC.mail>
Subject: Reset password instructions
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<p>Hello admin@example.com!</p>

<p>Someone has requested a link to change your password. You can do this through the link below.</p>

<p><a href="http://localhost:3000/administrators/password/edit?reset_password_token=mw7HiMvyZKCja9d7y9Hk">Change my password</a></p>

<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>

Redirected to 
Completed 500 Internal Server Error in 11074ms (ActiveRecord: 6.3ms | Allocations: 336198)


  
ArgumentError (Nil location provided. Can't build URI.):
  
actionpack (7.0.1) lib/action_dispatch/routing/polymorphic_routes.rb:212:in `polymorphic_method'
actionpack (7.0.1) lib/action_dispatch/routing/polymorphic_routes.rb:116:in `polymorphic_url'
actionpack (7.0.1) lib/action_dispatch/routing/url_for.rb:187:in `full_url_for'
actionpack (7.0.1) lib/action_dispatch/routing/url_for.rb:170:in `url_for'
actionpack (7.0.1) lib/action_controller/metal/redirecting.rb:144:in `_compute_redirect_to_location'
actionpack (7.0.1) lib/action_controller/metal/redirecting.rb:89:in `redirect_to'
actionpack (7.0.1) lib/action_controller/metal/flash.rb:62:in `redirect_to'
actionpack (7.0.1) lib/action_controller/metal/instrumentation.rb:42:in `block in redirect_to'
activesupport (7.0.1) lib/active_support/notifications.rb:206:in `block in instrument'
activesupport (7.0.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (7.0.1) lib/active_support/notifications.rb:206:in `instrument'
actionpack (7.0.1) lib/action_controller/metal/instrumentation.rb:41:in `redirect_to'
responders (3.0.1) lib/action_controller/responder.rb:147:in `redirect_to'
responders (3.0.1) lib/action_controller/responder.rb:207:in `navigation_behavior'
responders (3.0.1) lib/action_controller/responder.rb:174:in `rescue in to_html'
responders (3.0.1) lib/action_controller/responder.rb:171:in `to_html'
responders (3.0.1) lib/action_controller/responder.rb:165:in `respond'
responders (3.0.1) lib/action_controller/responder.rb:158:in `call'
responders (3.0.1) lib/action_controller/respond_with.rb:213:in `respond_with'
devise (4.8.1) app/controllers/devise/passwords_controller.rb:19:in `create'
actionpack (7.0.1) lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'
actionpack (7.0.1) lib/abstract_controller/base.rb:214:in `process_action'
actionpack (7.0.1) lib/action_controller/metal/rendering.rb:53:in `process_action'
actionpack (7.0.1) lib/abstract_controller/callbacks.rb:234:in `block in process_action'
activesupport (7.0.1) lib/active_support/callbacks.rb:118:in `block in run_callbacks'
actiontext (7.0.1) lib/action_text/rendering.rb:20:in `with_renderer'
actiontext (7.0.1) lib/action_text/engine.rb:69:in `block (4 levels) in <class:Engine>'
activesupport (7.0.1) lib/active_support/callbacks.rb:127:in `instance_exec'
activesupport (7.0.1) lib/active_support/callbacks.rb:127:in `block in run_callbacks'
activesupport (7.0.1) lib/active_support/callbacks.rb:138:in `run_callbacks'
actionpack (7.0.1) lib/abstract_controller/callbacks.rb:233:in `process_action'
actionpack (7.0.1) lib/action_controller/metal/rescue.rb:22:in `process_action'
actionpack (7.0.1) lib/action_controller/metal/instrumentation.rb:67:in `block in process_action'
activesupport (7.0.1) lib/active_support/notifications.rb:206:in `block in instrument'
activesupport (7.0.1) lib/active_support/notifications/instrumenter.rb:24:in `instrument'
activesupport (7.0.1) lib/active_support/notifications.rb:206:in `instrument'
actionpack (7.0.1) lib/action_controller/metal/instrumentation.rb:66:in `process_action'
actionpack (7.0.1) lib/action_controller/metal/params_wrapper.rb:259:in `process_action'
activerecord (7.0.1) lib/active_record/railties/controller_runtime.rb:27:in `process_action'
actionpack (7.0.1) lib/abstract_controller/base.rb:151:in `process'
actionview (7.0.1) lib/action_view/rendering.rb:39:in `process'
actionpack (7.0.1) lib/action_controller/metal.rb:188:in `dispatch'
actionpack (7.0.1) lib/action_controller/metal.rb:251:in `dispatch'
actionpack (7.0.1) lib/action_dispatch/routing/route_set.rb:49:in `dispatch'
actionpack (7.0.1) lib/action_dispatch/routing/route_set.rb:32:in `serve'
actionpack (7.0.1) lib/action_dispatch/routing/mapper.rb:18:in `block in <class:Constraints>'
actionpack (7.0.1) lib/action_dispatch/routing/mapper.rb:48:in `serve'
actionpack (7.0.1) lib/action_dispatch/journey/router.rb:50:in `block in serve'
actionpack (7.0.1) lib/action_dispatch/journey/router.rb:32:in `each'
actionpack (7.0.1) lib/action_dispatch/journey/router.rb:32:in `serve'
actionpack (7.0.1) lib/action_dispatch/routing/route_set.rb:850:in `call'
warden (1.2.9) lib/warden/manager.rb:36:in `block in call'
warden (1.2.9) lib/warden/manager.rb:34:in `catch'
warden (1.2.9) lib/warden/manager.rb:34:in `call'
rack (2.2.3) lib/rack/tempfile_reaper.rb:15:in `call'
rack (2.2.3) lib/rack/etag.rb:27:in `call'
rack (2.2.3) lib/rack/conditional_get.rb:40:in `call'
rack (2.2.3) lib/rack/head.rb:12:in `call'
actionpack (7.0.1) lib/action_dispatch/http/permissions_policy.rb:22:in `call'
actionpack (7.0.1) lib/action_dispatch/http/content_security_policy.rb:18:in `call'
rack (2.2.3) lib/rack/session/abstract/id.rb:266:in `context'
rack (2.2.3) lib/rack/session/abstract/id.rb:260:in `call'
actionpack (7.0.1) lib/action_dispatch/middleware/cookies.rb:693:in `call'
activerecord (7.0.1) lib/active_record/migration.rb:603:in `call'
actionpack (7.0.1) lib/action_dispatch/middleware/callbacks.rb:27:in `block in call'
activesupport (7.0.1) lib/active_support/callbacks.rb:99:in `run_callbacks'
actionpack (7.0.1) lib/action_dispatch/middleware/callbacks.rb:26:in `call'
actionpack (7.0.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (7.0.1) lib/action_dispatch/middleware/actionable_exceptions.rb:17:in `call'
actionpack (7.0.1) lib/action_dispatch/middleware/debug_exceptions.rb:28:in `call'
web-console (4.2.0) lib/web_console/middleware.rb:132:in `call_app'
web-console (4.2.0) lib/web_console/middleware.rb:28:in `block in call'
web-console (4.2.0) lib/web_console/middleware.rb:17:in `catch'
web-console (4.2.0) lib/web_console/middleware.rb:17:in `call'
actionpack (7.0.1) lib/action_dispatch/middleware/show_exceptions.rb:26:in `call'
railties (7.0.1) lib/rails/rack/logger.rb:36:in `call_app'
railties (7.0.1) lib/rails/rack/logger.rb:25:in `block in call'
activesupport (7.0.1) lib/active_support/tagged_logging.rb:99:in `block in tagged'
activesupport (7.0.1) lib/active_support/tagged_logging.rb:37:in `tagged'
activesupport (7.0.1) lib/active_support/tagged_logging.rb:99:in `tagged'
railties (7.0.1) lib/rails/rack/logger.rb:25:in `call'
sprockets-rails (3.4.2) lib/sprockets/rails/quiet_assets.rb:13:in `call'
actionpack (7.0.1) lib/action_dispatch/middleware/remote_ip.rb:93:in `call'
actionpack (7.0.1) lib/action_dispatch/middleware/request_id.rb:26:in `call'
rack (2.2.3) lib/rack/method_override.rb:24:in `call'
rack (2.2.3) lib/rack/runtime.rb:22:in `call'
activesupport (7.0.1) lib/active_support/cache/strategy/local_cache_middleware.rb:29:in `call'
actionpack (7.0.1) lib/action_dispatch/middleware/server_timing.rb:20:in `call'
actionpack (7.0.1) lib/action_dispatch/middleware/executor.rb:14:in `call'
actionpack (7.0.1) lib/action_dispatch/middleware/static.rb:23:in `call'
rack (2.2.3) lib/rack/sendfile.rb:110:in `call'
actionpack (7.0.1) lib/action_dispatch/middleware/host_authorization.rb:137:in `call'
railties (7.0.1) lib/rails/engine.rb:530:in `call'
puma (5.6.1) lib/puma/configuration.rb:252:in `call'
puma (5.6.1) lib/puma/request.rb:77:in `block in handle_request'
puma (5.6.1) lib/puma/thread_pool.rb:340:in `with_force_shutdown'
puma (5.6.1) lib/puma/request.rb:76:in `handle_request'
puma (5.6.1) lib/puma/server.rb:441:in `process_client'
puma (5.6.1) lib/puma/thread_pool.rb:147:in `block in spawn_thread'

Expected behavior

I should not be presented with errors after submitting the password reset form.

@iraline
Copy link

iraline commented Mar 31, 2022

Hi, did you try to add this:

config.navigational_formats = ['*/*', :html, :turbo_stream] in your config/initializers/devise.rb file ?

@bellatrix988
Copy link

I think it somehow related to #5446.
I created created a gist with the information might come in handy.

I resolved it by passing data: { turbo: false } in the form.

carlosantoniodasilva added a commit that referenced this issue Jan 31, 2023
Treat `:turbo_stream` request format as a navigational format, much like
HTML, so Devise/responders can work properly.

Allow configuring the `error_status` and `redirect_status` using the
latest responders features, via a new custom Devise responder, so we can
customize the both responses to match Hotwire/Turbo behavior, for
example with `422 Unprocessable Entity` and `303 See Other`,
respectively. The defaults aren't changing in Devise itself (yet), so it
still responds on errors cases with `200 OK`, and redirects on non-GET
requests with `302 Found`, but new apps are generated with the new
statuses and existing apps can opt-in. Please note that these defaults
might change in a future release of Devise.

PRs/Issues references:

#5545
#5529
#5516
#5499
#5487
#5467
#5440
#5410
#5340

#5542
#5530
#5519
#5513
#5478
#5468
#5463
#5458
#5448
#5446
#5439
carlosantoniodasilva added a commit that referenced this issue Jan 31, 2023
Treat `:turbo_stream` request format as a navigational format, much like
HTML, so Devise/responders can work properly.

Allow configuring the `error_status` and `redirect_status` using the
latest responders features, via a new custom Devise responder, so we can
customize the both responses to match Hotwire/Turbo behavior, for
example with `422 Unprocessable Entity` and `303 See Other`,
respectively. The defaults aren't changing in Devise itself (yet), so it
still responds on errors cases with `200 OK`, and redirects on non-GET
requests with `302 Found`, but new apps are generated with the new
statuses and existing apps can opt-in. Please note that these defaults
might change in a future release of Devise.

PRs/Issues references:

#5545
#5529
#5516
#5499
#5487
#5467
#5440
#5410
#5340

#5542
#5530
#5519
#5513
#5478
#5468
#5463
#5458
#5448
#5446
#5439
carlosantoniodasilva added a commit that referenced this issue Jan 31, 2023
Treat `:turbo_stream` request format as a navigational format, much like
HTML, so Devise/responders can work properly.

Allow configuring the `error_status` and `redirect_status` using the
latest responders features, via a new custom Devise responder, so we can
customize the both responses to match Hotwire/Turbo behavior, for
example with `422 Unprocessable Entity` and `303 See Other`,
respectively. The defaults aren't changing in Devise itself (yet), so it
still responds on errors cases with `200 OK`, and redirects on non-GET
requests with `302 Found`, but new apps are generated with the new
statuses and existing apps can opt-in. Please note that these defaults
might change in a future release of Devise.

PRs/Issues references:

#5545
#5529
#5516
#5499
#5487
#5467
#5440
#5410
#5340

#5542
#5530
#5519
#5513
#5478
#5468
#5463
#5458
#5448
#5446
#5439
carlosantoniodasilva added a commit that referenced this issue Jan 31, 2023
Treat `:turbo_stream` request format as a navigational format, much like
HTML, so Devise/responders can work properly.

Allow configuring the `error_status` and `redirect_status` using the
latest responders features, via a new custom Devise responder, so we can
customize the both responses to match Hotwire/Turbo behavior, for
example with `422 Unprocessable Entity` and `303 See Other`,
respectively. The defaults aren't changing in Devise itself (yet), so it
still responds on errors cases with `200 OK`, and redirects on non-GET
requests with `302 Found`, but new apps are generated with the new
statuses and existing apps can opt-in. Please note that these defaults
might change in a future release of Devise.

PRs/Issues references:

#5545
#5529
#5516
#5499
#5487
#5467
#5440
#5410
#5340

#5542
#5530
#5519
#5513
#5478
#5468
#5463
#5458
#5448
#5446
#5439
@carlosantoniodasilva
Copy link
Member

The main branch should contain all that's necessary for fully working with Turbo now, which should fix this. A new version will be released soon, but feel free to test it out from the main branch in the meantime, and report back on any issues. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

4 participants