Last active
June 8, 2019 02:58
-
-
Save envygeeks/8252474 to your computer and use it in GitHub Desktop.
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
def clean_for_action_based_url(url) | |
CGI.unescape(url || ""). | |
gsub(/\/+/, "/"). | |
tr('^a-z_-/', "") | |
end | |
def clean_url(url) | |
url = CGI.unescape(url || "") | |
url = url.gsub(/\A((https?:)?\/+)*/, "").gsub(/\/+/, "/") | |
url.split("/").map { |v| CGI.escape(v) }. | |
join("/").prepend("/") | |
end | |
redirect_to clean_url(params[:next]) # Without Rails | |
redirect_to root_path(params[:next], | |
only_path: true | |
) # Rails |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment