0.0
No commit activity in last 3 years
No release in over 3 years
See https://github.com/borot/rack-redirector.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

##What's this This is a simple redirector suited for Rack simple_router.

While Rack::Recursive requests another page internally, Rack::Redirector redirect to another page with 302 status code.

##Usage

####with simple_router

This is a simple sample that may not work but you will make sense of what can do with Rack::Redirector.

#config.ru
requrie 'rack/redirector'
require 'simple_router'

class MyApp

  include SimpleRouter::DSL
  
  get '/' do
    #do something..
  end

  get '/home' do
    authenticate
    #do something..
  end

  get '/input' do
    authenticate
    #show form and post to /create action
  end

  post '/create' do
    authenticate
    unless request.params.empty?
      #create record
      redirect '/home'
    else
      redirect '/input?mode=back'
    end
  end

  def call(env)
    #do something
  end

  class << self
    def redirect(location)
      raise RedirectRequest.new(location)
    end

    def authenticate
      redirect('/') unless current_user
    end
  end
end

run MyApp.new