Last active
October 31, 2021 02:36
-
-
Save Lordnibbler/7539651 to your computer and use it in GitHub Desktop.
Revisions
-
Lordnibbler revised this gist
Nov 19, 2013 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,8 @@ describe "Something", js: true do it "is a fake spec" do # this won't work in CI/test environments # 'another.localhost:3001' is not mapped in /etc/hosts visit foo_path(subdomain: 'another') end end -
Lordnibbler revised this gist
Nov 19, 2013 . 1 changed file with 15 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ module UrlHelper def with_subdomain(subdomain) subdomain = (subdomain || "") subdomain += "." unless subdomain.empty? [subdomain, request.domain].join end # allow link_to :subdomain => "" def url_for(options = nil) if options.kind_of?(Hash) && options.has_key?(:subdomain) options[:host] = with_subdomain(options.delete(:subdomain)) end super end end -
Lordnibbler created this gist
Nov 19, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ class DomainConstraint def initialize(domain) @domains = [domain].flatten end def matches?(request) request.subdomain.present? ? domain_to_match = request.subdomain + "." + request.domain : domain_to_match = request.domain @domains.include? domain_to_match 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,7 @@ require 'spec_helper' describe "Something", js: true do it "is a fake spec" do visit foo_path(subdomain: 'another') 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,5 @@ MyApp::Application.routes.draw do constraints DomainConstraint.new(['subdomain.domain.com', 'another.domain.com']) do resources :foo end end