class Upjs::Rails::Inspector
This object allows the server to inspect the current request for Up.js-related concerns such as “is this a page fragment update?”.
Available through the `#up` method in all controllers, helpers and views.
Public Class Methods
# File lib/upjs/rails/inspector.rb, line 10 def initialize(controller) @controller = controller end
Public Instance Methods
If the current request is a [fragment update](upjs.io/up.replace), this returns the CSS selector of the page fragment that should be updated.
The Up.js frontend will expect an HTML response containing an element that matches this selector. If no such element is found, an error is shown to the user.
Server-side code is free to optimize its response by only returning HTML that matches this selector.
# File lib/upjs/rails/inspector.rb, line 32 def target request.headers['X-Up-Target'] end
Forces Up.js to use the given string as the document title when processing this response.
This is useful when you skip rendering the `<head>` in an Up.js request.
# File lib/upjs/rails/inspector.rb, line 56 def title=(new_title) response.headers['X-Up-Title'] = new_title end
Returns whether the current request is an [page fragment update](upjs.io/up.replace) triggered by an Up.js frontend.
# File lib/upjs/rails/inspector.rb, line 18 def up? target.present? end
Returns whether the current form submission should be [validated](upjs.io/up-validate) (and not be saved to the database).
# File lib/upjs/rails/inspector.rb, line 39 def validate? validate_name.present? end
If the current form submission is a [validation](upjs.io/up-validate), this returns the name attribute of the form field that has triggered the validation.
# File lib/upjs/rails/inspector.rb, line 47 def validate_name request.headers['X-Up-Validate'] end
Private Instance Methods
# File lib/upjs/rails/inspector.rb, line 66 def params @controller.params end
# File lib/upjs/rails/inspector.rb, line 62 def request @controller.request end
# File lib/upjs/rails/inspector.rb, line 70 def response @controller.response end