Note that Merb::Dispatcher.handle is a private API and may change in the
future.
What specifically are you trying to achieve out of curiosity?
-- Yehuda
On Thu, Nov 27, 2008 at 4:37 PM, christocracy <[EMAIL PROTECTED]>wrote:
>
> I just over-rode Merb::Rack::Application#call to process multiple
> controller-requests.
>
> Has any one else done this yet? My implementation is very raw, just a
> proof-of-concept, but it works.
>
> I'm using this to process ajax requests where a certain param contains
> a json-encoded array of requests. each json-encoded request has an
> url param matching a standard Merb route.
>
> eg: requests: [{url: '/products/view/1}, {url: '/accounts/list'}]
>
> # if any request comes into /router, look for json-encoded array of
> requests in param "requests"
> if env["REQUEST_PATH"] == "/router"
> body = env[Merb::Const::RACK_INPUT]
> body.rewind if body.respond_to?(:rewind)
> json = body.read
>
> params = Merb::Parse.query(json)
> requests = JSON.parse(params["requests"])
>
> status = nil
> responses = []
> headers = nil
> rack_response = nil
>
> # iterates array of requests and dispatch to each controller.
> requests.each do |req|
> env["REQUEST_URI"] = req["url"]
> env["REQUEST_PATH"] = req["url"]
> rack_response = ::Merb::Dispatcher.handle(Merb::Request.new
> (env))
>
> responses << rack_response[2] # <-- capture each response
> body
> status = rack_response[0]
> headers = rack_response[1]
> end
>
> # compose a rack response from the array of responses. this is
> pretty ugly right now. assumes each
> # controller's action returned json.
> rack_response = [status, headers, "[" + responses.join(',') + "]"]
>
> else # <-- otherwise, do normal behaviour.
> rack_response = ::Merb::Dispatcher.handle(Merb::Request.new(env))
> end
> >
>
--
Yehuda Katz
Developer | Engine Yard
(ph) 718.877.1325
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"merb" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/merb?hl=en
-~----------~----~----~----~------~----~------~--~---