Created
September 18, 2012 22:56
-
-
Save jdx/3746550 to your computer and use it in GitHub Desktop.
mystique in route constraint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/routes.rb | |
require 'admin_constraint' | |
Tapjoyad::Application.routes.draw do | |
# ... | |
scope constraint: AdminConstraint.new do | |
resources :secure_things | |
end | |
# or... | |
mount Sidekiq::Web => "/sidekiq", constraints: AdminConstraint.new | |
# ... | |
end | |
# lib/admin_constraint.rb | |
class AdminConstraint | |
def matches?(request) | |
return false unless request.session[:tapjoy_id] | |
user = AdminUser.find_by_tapjoy_id(request.session[:tapjoy_id]) | |
!!user | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment