This request header contains the target selector that Unpoly updates when the server sends an error response.
An error response has a status code other than 2xx, but still contains HTML.
Server-side code is free to optimize its response to an error response by only rendering HTML that matches the provided selector. For example, you might prefer to not render an expensive sidebar if the sidebar is not targeted.
X-Up-Target: .menu
X-Up-Fail-Target: body
When submitting a form,
Unpoly needs to know whether the form submission has failed (to update the form with
validation errors) or succeeded (to update the [up-target] selector).
For Unpoly to be able to detect a failed form submission, the response must return a non-2xx HTTP status code. We recommend using HTTP 422 (Unprocessable Entity).
To do so in Ruby on Rails, pass a :status option to render:
class UsersController < ApplicationController
def create
user_params = params[:user].permit(:email, :password)
@user = User.new(user_params)
if @user.save
sign_in @user
else
render 'form', status: :unprocessable_entity
end
end
end
The example uses Ruby on Rails, but works similarly with any other backend.
Tip Your coding agent can search these docs locally with the Unpoly agent skill