RailsCasts Pro episodes are now free!

Learn more or hide this

C R's Profile

GitHub User: ciscoriordan

Comments by C R

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"