Sha256: 21b28a2f565acebd46bf7d4a62f2e7b664cf4ee12066cb58ca953b1be7ce38d1

Contents?: true

Size: 1.16 KB

Versions: 11

Compression:

Stored size: 1.16 KB

Contents

module Merb
  module Rack
    module Helpers
      
      # A helper to build a rack response which implements a redirect.  The status will be set to 
      # the passed in status if passed.  If you pass in permanent it will be a 301, permanent redirect,
      # otherwise it defaults to a temporary 302 redirect.  
      #
      # ==== Parameters
      # url<~to_s>:: The url to redirect to.
      # options<Hash>:: A hash of options for the redirect
      #   status: The status code to use for the redirect
      #   permanent:  True if this is a permanent redirect (301)
      #
      # ==== Returns
      # <Array>:: A rack response to redirect to the specified url.  
      #
      # @api plugin
      def self.redirect(url, options = {})
        # Build the rack array
        status   = options.delete(:status)
        status ||= options[:permanent] ? 301 : 302
        
        Merb.logger.info("Dispatcher redirecting to: #{url} (#{status})")
        Merb.logger.flush
        
        [status, { Merb::Const::LOCATION => url },
         Merb::Rack::StreamWrapper.new("<html><body>You are being <a href=\"#{url}\">redirected</a>.</body></html>")]
      end
      
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/merb-core-0.9.14/lib/merb-core/rack/helpers.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/merb-core-0.9.14/lib/merb-core/rack/helpers.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/merb-core-0.9.14/lib/merb-core/rack/helpers.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/merb-core-0.9.14/lib/merb-core/rack/helpers.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/merb-core-0.9.14/lib/merb-core/rack/helpers.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/merb-core-0.9.14/lib/merb-core/rack/helpers.rb
merb-core-0.9.10 lib/merb-core/rack/helpers.rb
merb-core-0.9.12 lib/merb-core/rack/helpers.rb
merb-core-0.9.11 lib/merb-core/rack/helpers.rb
merb-core-0.9.13 lib/merb-core/rack/helpers.rb
merb-core-0.9.9 lib/merb-core/rack/helpers.rb