1

It's a following of the Resque, Devise and admin authentication question.

Assuming we have:

User.last.role #=> 'admin'

New issue is: how to get an access to current user (as i have User.role which can be 'admin' or 'user') from this:

require 'resque/server'

class SecureResqueServer < Resque::Server

  before do
    #redirect '/login' unless current_user.role == 'admin'
  end

end

Thank you.

Community
  • 1
  • 1
There Are Four Lights
  • 1,406
  • 3
  • 19
  • 35

2 Answers2

0

I only have experience with authlogic and Resque, but this seems relevant:

http://blog.kiskolabs.com/post/776939029/rails3-resque-devise

The author updated his blog and suggests that you add the following to your routes, obviously tailoring it to your specific needs:

authenticate :admin do
  mount Resque::Server.new, :at => "/resque"
end
Peter Brown
  • 50,956
  • 18
  • 113
  • 146
0

Well, everything is much more simpler. To get current User instance directly from Warden, you just:

env['warden'].user

This way, using Devise, and roles system described above, you can:

require 'resque/server'

class SecureResqueServer < Resque::Server

  before do
    redirect '/login' unless env['warden'].user.role == 'admin'
  end
end
James P McGrath
  • 1,856
  • 1
  • 20
  • 35
There Are Four Lights
  • 1,406
  • 3
  • 19
  • 35