Module: Brut::FrontEnd::HandlingResults

Included in:
Handler, Page, RouteHook
Defined in:
lib/brut/front_end/handling_results.rb

Overview

Convienience methods to use inside handlers to make it easier to return richly typed results.

See Also:

Instance Method Summary collapse

Instance Method Details

#http_status(number) ⇒ Object

Return this to return an HTTP status code from a number or string containing the code.



22
# File 'lib/brut/front_end/handling_results.rb', line 22

def http_status(number) = Brut::FrontEnd::HttpStatus.new(number)

#redirect_to(klass, **query_string_params) ⇒ Object

Return this to cause your handler to redirect to klass' route with the given query string parameters.

be provided in query_string_params or this will raise an error. Note that the class must be for a GET route, since you cannot redirect to a non-GET.

Parameters:

  • klass (Class)

    A page or handler class whose route should be redirected-to. Note that if parameters are required, they must

  • query_string_params (Hash)

    arguments and parameters for the route. Any values that correspond to route parameters will be used to build the route. A value of 'anchor' will be used as the hash/anchor part of the URL and should not contain a hash sign. Remaining will be used as query parameters.

Raises:



14
15
16
17
18
19
# File 'lib/brut/front_end/handling_results.rb', line 14

def redirect_to(klass, **query_string_params)
  if !klass.kind_of?(Class)
    raise ArgumentError,"redirect_to should be given a Class, not a #{klass.class}"
  end
  Brut.container.routing.path(klass,with_method: :get,**query_string_params)
end