문제

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.

도움이 되었습니까?

해결책 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

다른 팁

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
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top