module Hanami::Action::Redirect
HTTP redirect API
@since 0.1.0
Constants
- LOCATION
The HTTP header for redirects
@since 0.2.0 @api private
Private Instance Methods
redirect_to(url, status: 302)
click to toggle source
Redirect
to the given URL and halt the request
@param url [String] the destination URL @param status [Fixnum] the http code
@since 0.1.0
@see Hanami::Action::Throwable#halt
@example With default status code (302)
require 'hanami/controller' class Create include Hanami::Action def call(params) # ... redirect_to 'http://example.com/articles/23' end end action = Create.new action.call({}) # => [302, {'Location' => '/articles/23'}, '']
@example With custom status code
require 'hanami/controller' class Create include Hanami::Action def call(params) # ... redirect_to 'http://example.com/articles/23', status: 301 end end action = Create.new action.call({}) # => [301, {'Location' => '/articles/23'}, '']
# File lib/hanami/action/redirect.rb, line 53 def redirect_to(url, status: 302) headers[LOCATION] = ::String.new(url) halt(status) end