Marten::Handlers::Schema
Inherits Marten::Handlers::Schema::Callbacks / Marten::Handlers::Template / Marten::Handlers::Rendering / Marten::Handlers::Base / Marten::Handlers::XFrameOptions / Marten::Handlers::ContentSecurityPolicy / Marten::Handlers::Session / Marten::Handlers::RequestForgeryProtection / Marten::Handlers::Flash / Marten::Handlers::Cookies / Marten::Handlers::ExceptionHandling / Marten::Handlers::Callbacks / Marten::Core::DebugModeLoggable / Reference / Object
Handler allowing to process a form through the use of a schema.
This handler can be used to process a form and validate its data through the use of a schema. It is expected that the handler will be accessed through a GET request first: when this happens the configured template is rendered and displayed, and the configured schema which is initialized can be accessed from the template context in order to render a form for example. When the form is submitted via a POST request, the configured schema is validated using the form data. If the data is valid, the handler returns an HTTP redirect to a configured success URL.
class MyFormHandler < Marten::Handlers::Schema
schema MyFormSchema
template_name "my_form.html"
success_route_name "my_form_success"
end
It should be noted that the redirect response issued will be a 302 (found).
The schema used to perform the validation can be defined through the use of the #schema macro. Alternatively,
the #schema_class method can also be overridden to dynamically define the schema class as part of the request
handling.
The #template_name class method allows to define the name of the template to use to render the schema while the
#success_route_name method can be used to specify the name of a route to redirect to once the schema has been
validated. Alternatively, the #sucess_url class method can be used to provide a raw URL to redirect to. The same
method can also be overridden at the instance level in order to rely on a custom logic to generate the sucess URL
to redirect to.
Class methods
Allows to configure the name to use to include the schema into the template context.
Returns the name to use to include the schema object into the template context (defaults to schema).
Allows to set the route name that should be resolved to produce the URL to when processing a valid schema.
Returns the route name that should be resolved to produce the URL to redirect to when processing a valid schema.
Defaults to nil.
Allows to configure a raw URL to redirect to when processing a valid schema.
Returns the configured raw URL to redirect when processing a valid schema.
Defaults to nil.
Instance methods
Handles a POST HTTP request and returns a Marten::HTTP::Response object.
The default implementation will return a 405 (not allowed) response.
Produces the response when the processed schema is invalid.
By default, this will render the configured template and return a corresponding HTTP response.
Produces the response when the processed schema is valid.
By default, this will return a 302 redirect targetting the configured success URL.
Handles a PUT HTTP request and returns a Marten::HTTP::Response object.
The default implementation will return a 405 (not allowed) response.
Returns the URL to redirect to after the schema has been validated and processed.
By default, the URL will be determined from the configured #success_url and #success_route_name values. This
method can be overridden on subclasses in order to define any arbitrary logics that might be necessary in order
to determine the schema success URL.
Macros
Allows to configure the schema class that should be used to process request data.