Created
August 26, 2013 12:23
-
-
Save 0xGGGGG/6340887 to your computer and use it in GitHub Desktop.
render respecting subdomains.
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
module ApplicationHelper | |
def render_respecting_subdomain(options = nil, extra_options = {}, &block) | |
raw render(sanitized_options_from(options, request.subdomain), extra_options, &block) | |
rescue ActionView::MissingTemplate | |
raw render(sanitized_options_from(options, "default"), extra_options, &block) | |
end | |
def sanitized_options_from(args, subdomain = "") | |
return args unless subdomain.present? | |
if args.is_a?(String) | |
"subdomains/#{subdomain}/#{args}" if subdomain.present? | |
elsif args.is_a?(Hash) && args[:partial] | |
args.merge({ partial: "subdomains/#{subdomain}/#{args[:partial]}" }) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment