title: Possible to use route helpers to redirect from a Rack app in Rails 3?
body: <p>I have a simple url shortener that base 62 encodes my Developer model's id number and returns something like this as a url:</p>
  
  <pre><code>http://example.com/d/dYbZ
  </code></pre>
  
  <p>I've mounted a rack app in my <code>routes.rb</code> file thusly:</p>
  
  <pre><code>  match '/d/:token' =&gt; DeveloperRedirectApp
  </code></pre>
  
  <p>... and my simple Rack app looks like this:</p>
  
  <pre><code>class DeveloperRedirectApp
    # no worky:
    #def initialize(app)
    #  @app = app
    #end
  
    def self.call(env)
      request = Rack::Request.new(env)
      token = request.path_info.sub("/d/", "")
      dev_id = token.b(62).to_s(10)
      if dev = Developer.find_by_id(dev_id)
        # developer_path also doesn't work since @app is not defined
        location = @app.developer_path(dev)
      else
        # same here
        location = @app.root_path
      end
      [301, {"Location" =&gt; location}, self]
    end  
  
    def self.each(&amp;block)
    end
  end
  </code></pre>
  
  <p>The problem is... apparently the initialize call is only sent a rails app instance if it's an actual middleware, not simply a rack app mounted in the routes file. A middleware doesn't make sense to me since this only needs to run if a url of the form <code>/d/:token</code> is requested, not on every request.</p>
  
  <p>I'm just trying to do a simple base 62 decode, then redirect to the decoded developer id (if it exists, redirect to root_url otherwise). Is there a way to access the route helpers (ie, <code>developer_path</code>) or simply a better way to do this?</p>