Created
June 18, 2013 20:47
-
-
Save delba/5809200 to your computer and use it in GitHub Desktop.
Constraints in routes
This file contains hidden or 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/initializers/contraints.rb | |
| module Constraints | |
| class Subdomain | |
| def self.matches?(request) | |
| request.subdomain.present? && request.subdomain != 'www' | |
| end | |
| end | |
| class SignedIn | |
| def self.matches?(request) | |
| !!request.session[:user_id] | |
| # !!request.cookies['user_id'] | |
| end | |
| end | |
| end |
This file contains hidden or 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
| Sample::Application.routes.draw do | |
| constraints Constraints::SignedIn do | |
| get '/' => 'items#index' | |
| end | |
| root 'dashboard#index' | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment