views:

71

answers:

1

I'm trying to get a sinatra app as a subpath in my rails 3 app. Specifically, the resque queuing system has a sinatra based web interface that I would like to have accessible through /resque on my usual rails app.

You can see the project here: http://github.com/defunkt/resque

I found some people talking about adding a rackup file and doing this sort of thing:

run Rack::URLMap.new( \
  "/" => ActionController::Dispatcher.new,
  "/resque" => Resque::Server.new
)

But I don't really know where to put that or how to make it run. My deployment is with passenger, but it would me nice to also have it running when I run 'rails server' too. Any suggestions?

--edit--

I've made some progress by putting the following in config/routes.rb:

match '/resque(/:page)', :to => Rack::URLMap.new("/resque" => Resque::Server.new)

Which seems to work pretty well, however it loses the public folder, (which is defined within the gem I guess), and as a result, there is no styling information, nor images.

+3  A: 

You can setup any rack endpoint as a route in rails 3. This guide by wycats goes over what you are looking for and many of the other things you can do in rails3:

http://yehudakatz.com/2009/12/26/the-rails-3-router-rack-it-up/

For example:

class HomeApp < Sinatra::Base
  get "/" do
    "Hello World!"
  end
end

Basecamp::Application.routes do
  match "/home", :to => HomeApp
end
Scott S.
Thanks! That's what I was looking for. But the URLs don't map to the root. I.e. all the urls passed to HomeApp start with '/home'. Is there a way to remap them?
zaius
Just replace `match "/home"` with `match "/"`?
Ryan Bigg
That will map all the routes to the sinatra app. I want /resque/home to call /home in the sinatra app. The only solution I can think of is to mess with the Rack env and strip down the path.
zaius
OK I tried rewriting env['PATH_INFO'] and it breaks all the redirects, etc., so that probably won't work.
zaius
@zaius Maybe this'll help http://stackoverflow.com/questions/3026200/specifying-entire-path-as-optional-rails-3-0-0/3139056#3139056
andi
@zaius I haven't played with it much, but I believe you would route /resque to the sinatra app, and it would handle /home itself.
Scott S.