Repository: heartcombo/devise

Issue #5446: Rails 7 devise flash messages not being shown
Created: 2021-12-30T14:59:14Z
Environment

Ruby 3.0.2p107
Rails 7.0.0
Devise 4.8.1

Current behavior
A new rails 7 app with devise.
Flash messages from Devise are not shown but Flash messages generated from another controller are shown.
The Devise flash messages appear to be being generated in the console rendering messages when a new user is registered with a password that is too short

Started POST "/users" for ::1 at 2021-12-24 08:02:10 +0000
Processing by Devise::RegistrationsController#create as TURBO_STREAM
  Parameters: {"authenticity_token"=>"[FILTERED]", "user"=>{"email"=>"asdf@asdf.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up"}
  TRANSACTION (0.1ms)  begin transaction
  User Exists? (2.7ms)  SELECT 1 AS one FROM "users" WHERE "users"."email" = ? LIMIT ?  [["email", "asdf@asdf.com"], ["LIMIT", 1]]
  TRANSACTION (0.2ms)  rollback transaction
  Rendering layout layouts/application.html.erb
  Rendering /home/sroot/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/devise-4.8.1/app/views/devise/registrations/new.html.erb within layouts/application
  Rendered /home/sroot/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/devise-4.8.1/app/views/devise/shared/_error_messages.html.erb (Duration: 0.7ms | Allocations: 582)
  Rendered /home/sroot/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/devise-4.8.1/app/views/devise/shared/_links.html.erb (Duration: 0.2ms | Allocations: 92)
  Rendered /home/sroot/.rbenv/versions/3.0.2/lib/ruby/gems/3.0.0/gems/devise-4.8.1/app/views/devise/registrations/new.html.erb within layouts/application (Duration: 3.9ms | Allocations: 2199)
  Rendered layout layouts/application.html.erb (Duration: 77.5ms | Allocations: 4429)
Completed 200 OK in 473ms (Views: 78.7ms | ActiveRecord: 3.1ms | Allocations: 15288)


Example minimal app:
https://github.com/steveroot/rails7deviseflash
(Add a 'new club' to see working flash message, Register a new user with a short password to not see flash message yet see render message in console)
Expected behavior
Flash messages shown on screen when generated

Duplicate issue #5468: Getting ArgumentError (Nil location provided. Can't build URI.) after submitting password reset form on development
Created: 2022-02-10T13:21:39Z
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.

Closing comment (2022-09-12T15:28:32Z): 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.