Rails 3, Resque, and Devise

Update 1: These instructions should work just fine for any Rack application mounted in Rails 3.

Update 2: After talking to José Valim about this, it turns out that in the latest Device (1.1rc2 and up) you can also do this in the routes file, like this:

Update 3: If you’re having problems with the Resque web interface static assets you’ll need to either copy or symlink them from the gem to your app’s public directory. The static assets are in lib/resque/server/public/ in the Resque gem directory (find out where that is with bundle show resque).

So you have your fancy new Rails 3 app working with some Resque awesomeness, but now you’d like to integrate the Resque web interface into your administration. Easy with Rails 3’s new mountable Rack apps!

First of all add the resque gem to your Gemfile:

And add this line to your config/routes.rb:

Then fire up your preferred app server and navigate to http://localhost:3000/resque

This is great and all, but now all and sundry can access your queues and wreak all sorts of havoc. Devise and Rack to the rescue (pun not intended).

Create a new initializer (config/initializers/resque.rb) with the following code:

Make sure to change the scope to what ever is appropriate for you application. You might also need to adjust the strategies being used (in our case database_authenticatable and rememberable).

// matt

// joao