Skip to content
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,8 @@ Devise.setup do |config|
# apps is `200 OK` and `302 Found` respectively, but new apps are generated with
# these new defaults that match Hotwire/Turbo behavior.
# Note: These might become the new default in future versions of Devise.
config.responder.error_status = :unprocessable_entity
config.responder.error_status = :unprocessable_content # for Rack 3.1 or higher
# config.responder.error_status = :unprocessable_entity # for Rack 3.0 or lower

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

config.responder.redirect_status = :see_other
end
```
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/devise/confirmations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def show
set_flash_message!(:notice, :confirmed)
respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
else
# TODO: use `error_status` when the default changes to `:unprocessable_entity`.
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
# Use `error_status` when the default changes to `:unprocessable_content` (or `:unprocessable_entity`).
respond_with_navigational(resource.errors, status: (Devise.responder.error_status != :ok) ? Devise.responder.error_status : Rack::Utils::SYMBOL_TO_STATUS_CODE.key(422) ){ render :new }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's revert these controller changes and continue using :unprocessable_entity from here. I'll revisit with responders later, but for now we can rely on the fact that Rails will transparently handle it for us depending on the Rack version.

(I'm still considering making these code changes for v5, not sure it's something I want to bite just yet, as things have been working just fine for now, and there's already plenty of changes on v5 for people to upgrade... maybe in the next version)

end
end

Expand Down
4 changes: 2 additions & 2 deletions app/controllers/devise/unlocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def show
set_flash_message! :notice, :unlocked
respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) }
else
# TODO: use `error_status` when the default changes to `:unprocessable_entity`.
respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
# Use `error_status` when the default changes to `:unprocessable_content` (or `:unprocessable_entity`).
respond_with_navigational(resource.errors, status: (Devise.responder.error_status != :ok) ? Devise.responder.error_status : Rack::Utils::SYMBOL_TO_STATUS_CODE.key(422) ){ render :new }
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/generators/templates/devise.rb
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
# apps is `200 OK` and `302 Found` respectively, but new apps are generated with
# these new defaults that match Hotwire/Turbo behavior.
# Note: These might become the new default in future versions of Devise.
config.responder.error_status = :unprocessable_entity
config.responder.error_status = <%= Rack::Utils::SYMBOL_TO_STATUS_CODE.key(422).inspect %>
config.responder.redirect_status = :see_other

# ==> Configuration for :registerable
Expand Down