This request header contains the target selector for a failed fragment update.
A fragment update is considered failed if the server responds with a status code other than 2xx, but still renders HTML.
Server-side code is free to optimize its response to a failed request 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 via AJAX
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 be return a non-2xx HTTP status code. We recommend to use 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