Created
          January 24, 2017 14:31 
        
      - 
      
- 
        Save DonKoko/3e4520bd871bec332604d10465898816 to your computer and use it in GitHub Desktop. 
    CustomDomain rails
  
        
  
    
      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
    
  
  
    
  | @tournament_season = | |
| if CustomDomain.where(:domain => request.host).any? | |
| CustomDomain.where(:domain => request.host).first.tournament_season | |
| else | |
| TournamentSeason.find(params[:id]) | |
| 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
    
  
  
    
  | class CustomDomainConstraint | |
| def self.matches?(request) | |
| CustomDomain.where(:domain => request.host).any? | |
| end | |
| end | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Here's a tweaked approach using
find_by:Another round of tweaks could lead you to just move the custom domain bit into a separate private method in your controller:
Just some ideas for you to consider. Best of luck!