NoMethodError in Devise::RegistrationsController#create

On submitting the sign up form, you may run into this error:
NoMethodError in Devise::RegistrationsController#create

undefined method `user_url' for #<Devise::RegistrationsController:0x0000000000da98>

Did you mean?
           
       
purchase_url
Extracted source (around line #233):
    if options.empty?
      recipient.public_send(method, *args)
    else
      recipient.public_send(method, *args, options)
    end

Why it happens


This error occurs because of the changes in the way Rails responds to form submissions and redirects. From the devise documentation:
 Devise (and Responders) have historically responded with 200 OK for form validation errors, and redirected with 302 Found, both of which have been the Rails defaults for rendering and redirects. Since Hotwire/Turbo, Rails has been changing its defaults to better match this new expected behavior of responding with 422 Unprocessable Entity and redirecting non-GET requests with 303 See Other.

How to fix it


You can fix it by upgrading devise to version 4.9 or above. In your Gemfile, change the devise version:
gem "devise", "~> 4.9"

Then run:
bundle update devise

You can (optionally) also add the following configuration to the devise initializer file:
# config/initializers/devise.rb
Devise.setup do |config|
  # ...
  config.responder.error_status = :unprocessable_entity
  config.responder.redirect_status = :see_other
  # ...
end