Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Cisco Riordan's Profile

GitHub User: ciscoriordan

Site: http://www.ciscoriordan.com

Comments by Cisco Riordan

Avatar

Thanks. If you use .try(:admin) instead, the redirect works correctly even if you aren't logged in:

ruby
require 'resque/server'

class Resque::SecureResqueServer < Resque::Server
  before do
    redirect '/' unless request.env['warden'].user.try(:admin)
  end
end

That also uses the Resque:: namespace and is loaded by Rails automatically if you use it in e.g. app/initializers/resque_auth.rb.

In your routes.rb, you would include:

ruby
mount Resque::SecureResqueServer, :at => "/resque"