Skip to content

Instantly share code, notes, and snippets.

@milushov
Created April 12, 2014 21:54
Show Gist options
  • Save milushov/10558803 to your computer and use it in GitHub Desktop.
Save milushov/10558803 to your computer and use it in GitHub Desktop.
def current_page?(options)
unless request
raise "You cannot use helpers that need to determine the current " \
"page unless your view context provides a Request object " \
"in a #request method"
end
return false unless request.get? || request.head?
url_string = URI.parser.unescape(url_for(options)).force_encoding(Encoding::BINARY)
# We ignore any extra parameters in the request_uri if the
# submitted url doesn't have any either. This lets the function
# work with things like ?order=asc
request_uri = url_string.index("?") ? request.fullpath : request.path
request_uri = URI.parser.unescape(request_uri).force_encoding(Encoding::BINARY)
binding.pry
if url_string =~ /^\w+:\/\//
url_string == "#{request.protocol}#{request.host_with_port}#{request_uri}"
else
url_string == request_uri
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment