Sha256: b9b3b9f9d11c1474ab2d18258c65b7d14e462b5eafcfa7f9d76d6287e15c90b4

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

#          Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
# All files in this distribution are subject to the terms of the Ruby license.

module Ramaze

  # RedirectHelper actually takes advantage of LinkHelper.link_raw to build the links
  # it redirects to.
  # It doesn't do much else than this:
  #     setting a status-code of 303 and a response['Location'] = link
  # returning some nice text for visitors who insist on ignoring those hints :P
  #
  # example of usage:
  #   redirect MainController
  #   redirect MainController, :foo
  #   redirect 'foo/bar'
  #   redirect :index, :status => 309
  #
  # TODO:
  #   - maybe some more options, like a delay
  #

  module RedirectHelper

    private

    # Usage:
    #   redirect R(MainController)
    #   redirect R(MainController, :foo)
    #   redirect 'foo/bar'

    def redirect target, opts = {}
      target = target.to_s
      head = {
        'Location' => target
      }.merge(response.header)

      status = opts[:status] || STATUS_CODE["See Other"]

      body = %{Please follow <a href="#{target}">#{target}</a>!}


      throw(:redirect, :body => body, :status => status, :head => head)
    end

    # redirect to the location the browser says it's coming from.

    def redirect_referer
      redirect request.referer
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ramaze-0.1.2 lib/ramaze/helper/redirect.rb
ramaze-0.1.1 lib/ramaze/helper/redirect.rb
ramaze-0.1.3 lib/ramaze/helper/redirect.rb