class Marten::Handlers::RecordDelete

Overview

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.

Included Modules

Extended Modules

Defined in:

marten/handlers/record_delete.cr

Class Method Summary

Instance Method Summary

Instance methods inherited from module Marten::Handlers::RecordRetrieving

model model, queryset queryset, record record

Macros inherited from module Marten::Handlers::RecordRetrieving

model(model_klass) model, queryset(queryset) queryset

Instance methods inherited from class Marten::Handlers::Template

get get

Class methods inherited from class Marten::Handlers::Template

content_type : String | Nil content_type, template_name : String | Nil template_name

Instance methods inherited from module Marten::Handlers::Rendering

content_type : String content_type, render_to_response(context : Hash | NamedTuple | Nil | Marten::Template::Context = nil, status : ::HTTP::Status | Int32 = 200) render_to_response, template_name : String template_name

Instance methods inherited from class Marten::Handlers::Base

context context, delete delete, dispatch : Marten::HTTP::Response dispatch, get get, head(status : ::HTTP::Status | Int32) : HTTP::Response
head
head
, json(raw_json : String, status : ::HTTP::Status | Int32 = 200)
json(serializable, status : ::HTTP::Status | Int32 = 200)
json
, options options, params : Marten::Routing::MatchParameters params, patch patch, post post, put put, redirect(url : String, permanent = false) redirect, render(template_name : String, context : Hash | NamedTuple | Nil | Marten::Template::Context = nil, content_type = HTTP::Response::DEFAULT_CONTENT_TYPE, status : ::HTTP::Status | Int32 = 200) render, request : Marten::HTTP::Request request, respond(streamed_content : Iterator(String), content_type = HTTP::Response::DEFAULT_CONTENT_TYPE, status : ::HTTP::Status | Int32 = 200)
respond(content = "", content_type = HTTP::Response::DEFAULT_CONTENT_TYPE, status : ::HTTP::Status | Int32 = 200)
respond
, response : Marten::HTTP::Response? response, response! response!, reverse(*args, **options)
reverse(*args, **options, &)
reverse
, trace trace

Constructor methods inherited from class Marten::Handlers::Base

new(request : HTTP::Request, params : Routing::MatchParameters)
new(request : HTTP::Request, **kwargs)
new

Class methods inherited from class Marten::Handlers::Base

content_security_policy_block content_security_policy_block, http_method_names
http_method_names(*method_names : String | Symbol)
http_method_names

Instance methods inherited from module Marten::Handlers::Session

session(*args, **options)
session(*args, **options, &)
session

Instance methods inherited from module Marten::Handlers::RequestForgeryProtection

get_csrf_token get_csrf_token, referer_trusted? referer_trusted?

Instance methods inherited from module Marten::Handlers::Flash

flash(*args, **options)
flash(*args, **options, &)
flash

Instance methods inherited from module Marten::Handlers::Cookies

cookies(*args, **options)
cookies(*args, **options, &)
cookies

Macros inherited from module Marten::Handlers::Callbacks

after_dispatch(*names) after_dispatch, before_dispatch(*names) before_dispatch, before_render(*names) before_render

Class Method Detail

def self.lookup_field : String #

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


def self.record_context_name(name : String | Symbol) #

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


[View source]
def self.record_context_name : String #

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


[View source]
def self.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.


[View source]
def self.success_route_name : String | Nil #

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

Defaults to nil.


[View source]
def self.success_url(success_url : String | Nil) #

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


[View source]
def self.success_url : String | Nil #

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

Defaults to nil.


[View source]

Instance Method Detail

def post #
Description copied from class Marten::Handlers::Base

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

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


[View source]
def 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.


[View source]