class

Marten::Handlers::RecordDelete

Inherits Marten::Handlers::RecordRetrieving / 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 delete a specific model record.

This handler can be used to delete an existing model record for POST requests. Optionally the handler can be accessed with GET request and a template can be displayed in this case; this allows to show a confirmation page to users before deleting the record:

class ArticleDeleteHandler < Marten::Handlers::RecordDelete
  model MyModel
  template_name "article_delete.html"
  success_route_name "article_delete_success"
end

It should be noted that the redirect response issued will be a 302 (found).

The #template_name class method allows to define the name of the template to use to render a deletion confirmation page while the #success_route_name method can be used to specify the name of a route to redirect to once the deletion is complete. 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

lookup_field

Returns the name of the model field that will be used to retrieve the record (defaults to pk).

record_context_name(name : String | Symbol)

Allows to configure the name to use to include the model record into the template context.

Source
record_context_name

Returns the name to use to include the model record into the template context (defaults to record).

Source
success_route_name(success_route_name : String | Nil)

Allows to set the route name that should be resolved to produce the URL to redirect to after the deletion.

Source
success_route_name

Returns the route name that should be resolved to produce the URL to redirect to after deleting the record.

Defaults to nil.

Source
success_url(success_url : String | Nil)

Allows to configure a raw URL to redirect to after the deletion

Source
success_url

Returns the configured raw URL to redirect to after deleting the record.

Defaults to nil.

Source

Instance methods

post

Handles a POST HTTP request and returns a Marten::HTTP::Response object.

The default implementation will return a 405 (not allowed) response.

Source
success_url

Returns the URL to redirect to after the deletion is complete.

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 deletion success URL.

Source