Question

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.

Was it helpful?

Solution 2

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

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top