forked from prepor/subdomain_routes
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split URL writing and rewriting into separate files. Finished tests f…
…or URL writing.
- Loading branch information
Showing
5 changed files
with
169 additions
and
90 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module SubdomainRoutes | ||
module UrlWriter | ||
def self.included(base) | ||
base.alias_method_chain :url_for, :subdomains | ||
end | ||
|
||
def url_for_with_subdomains(options) | ||
if subdomain = options.delete(:subdomain) | ||
host = options[:host] || default_url_options[:host] | ||
raise "Missing host to link to! Please provide :host parameter or set default_url_options[:host]" unless host | ||
first_part, *other_parts = host.split(".") | ||
if subdomain.to_s != first_part | ||
options[:only_path] = false | ||
options[:host] = other_parts.unshift(subdomain).join('.') | ||
end | ||
end | ||
url_for_without_subdomains(options) | ||
end | ||
end | ||
end | ||
|
||
ActionController::UrlWriter.send :include, SubdomainRoutes::UrlWriter |
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
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