Method: Nesta::View::Helpers#path_to
- Defined in:
- lib/nesta/helpers.rb
#path_to(page_path, options = {}) ⇒ Object
Generates the full path to a given page, taking Rack routers and reverse proxies into account.
Takes an options hash with a single option called ‘uri`. Set it to `true` if you’d like the publicly accessible URI for the path, rather than just the path relative to the site’s root URI. The default is ‘false`.
path_to(page.abspath, uri: true)
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/nesta/helpers.rb', line 83 def path_to(page_path, = {}) host = '' if [:uri] host << "http#{'s' if request.ssl?}://" if (request.env.include?("HTTP_X_FORWARDED_HOST") or request.port != (request.ssl? ? 443 : 80)) host << request.host_with_port else host << request.host end end uri_parts = [host] uri_parts << request.script_name.to_s if request.script_name uri_parts << page_path File.join(uri_parts) end |