Module: Innate::Helper::Redirect

### Home Classes Methods

### In Files

- lib/innate/helper/redirect.rb

### Methods

- #raw_redirect
- #redirect
- #redirect_body
- #redirect_referer
- #redirect_referrer
- #respond
- #respond!

### Class/Module Index

Quicksearch

- Innate
- Innate::Action
- Innate::Adapter
- Innate::Cache
- Innate::Cache::API
- Innate::Cache::DRb
- Innate::Cache::FileBased
- Innate::Cache::Marshal
- Innate::Cache::Memory
- Innate::Cache::YAML
- Innate::Current
- Innate::Etanni
- Innate::Helper
- Innate::Helper::Aspect
- Innate::Helper::Aspect::SingletonMethods
- Innate::Helper::CGI
- Innate::Helper::Flash
- Innate::Helper::Link
- Innate::Helper::Redirect
- Innate::Helper::Render
- Innate::HelperAccess
- Innate::HelpersHelper
- Innate::LRUHash
- Innate::LogHub
- Innate::Mock
- Innate::Mock::Session
- Innate::Node
- Innate::Optioned
- Innate::Optioned::SingletonMethods
- Innate::Options
- Innate::Request
- Innate::Response
- Innate::Rewrite
- Innate::Route
- Innate::Session
- Innate::Session::Flash
- Innate::SingletonMethods
- Innate::StateAccessor
- Innate::Traited
- Innate::Trinity
- Innate::URLMap
- Innate::View
- Innate::View::ERB
- Innate::View::Etanni
- Innate::View::None
- Logger
- Logger::ColorFormatter
- Object

No matching classes.

# Innate::Helper::Redirect

### Public Instance Methods

raw_redirect(target, options = {}, &block) click to toggle source

    # File lib/innate/helper/redirect.rb, line 59
    def raw_redirect(target, options = {}, &block)
      header = response.header.merge('Location' => target.to_s)
      status = options[:status] || 302
      body   = options[:body] || redirect_body(target)

      Log.debug "Redirect to: #{target}"
      throw(:redirect, Response.new(body, status, header, &block))
    end

redirect(target, options = {}) click to toggle source

`target` should be anything responding to to_s. To check or modify the URI the redirect will go to you may pass a block, the result value of the block is ignored:

    redirect("/"){|uri| uri.scheme = 'http' }
    redirect("/"){|uri| uri.host = 'secure.com' if uri.scheme =~ /s/ }

`options` may contain:

    :scheme => "http" | "https" | "ftp" | ...
    :host   => "localhost" | "foo.com" | "123.123.123.123" | ...
    :port   => 7000 | "80" | 80 | ...

    :status => 302 | 300 | 303 | ...
    :body   => "This is a redirect, hold on while we teleport" | ...

    :raw!   => true | false | nil | ...

Note that all options are optional and you may just pass a `target`.

    # File lib/innate/helper/redirect.rb, line 38
    def redirect(target, options = {})
      target = target.to_s

      case target
      when /^http/, /^\//
        uri = URI(target)
      else
        uri = URI("/#{target}")
      end

      uri.scheme ||= options[:scheme] || request.scheme
      uri.host   ||= options[:host]   || request.host
      uri.port   ||= options[:port]   || request.port

      uri = URI(uri.to_s)

      yield(uri) if block_given?

      raw_redirect(uri, options)
    end

redirect_body(target) click to toggle source

    # File lib/innate/helper/redirect.rb, line 68
    def redirect_body(target)
      "You are being redirected, please follow this link to: " +
        "<a href='#{target}'>#{h target}</a>!"
    end

redirect_referer(fallback = Innate.options.prefix) click to toggle source
Alias for: redirect_referrer
redirect_referrer(fallback = Innate.options.prefix) click to toggle source

    # File lib/innate/helper/redirect.rb, line 73
    def redirect_referrer(fallback = Innate.options.prefix)
      if (referer = request.env['HTTP_REFERER']) && (url = request.url)
        referer_uri, request_uri = URI(referer), URI(url)

        redirect(referer) unless referer_uri == request_uri
      end

      redirect(fallback)
    end

Also aliased as: redirect_referer
respond(body, status = 200, header = {}) click to toggle source

    # File lib/innate/helper/redirect.rb, line 4
    def respond(body, status = 200, header = {})
      response.write body
      response.status = status
      header['Content-Type'] ||= Response.mime_type
      header.each{|key, value| response[key] = value }

      throw(:respond, response)
    end

respond!(body, status = 200, header = {}) click to toggle source

    # File lib/innate/helper/redirect.rb, line 13
    def respond!(body, status = 200, header = {})
      header['Content-Type'] ||= Response.mime_type
      throw(:respond, Response.new(body, status, header))
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.