Skip to content

Instantly share code, notes, and snippets.

@narath
Created January 5, 2023 13:27
Show Gist options
  • Save narath/2c39f95fc3994662de6f06c98b0d2ed4 to your computer and use it in GitHub Desktop.
Save narath/2c39f95fc3994662de6f06c98b0d2ed4 to your computer and use it in GitHub Desktop.
Regular expression for changing the localhost domain
# in general you should never need to use this in Rails
# since you should use the url helpers
# this is a really helpful post about how to do this elegantly with a concern
# https://andycroll.com/ruby/url-helpers-outside-views-controllers/
def change_localhost_domain(url, new_domain)
url.gsub(/http:\/\/localhost:3000|http:\/\/127.0.0.1:3000/, new_domain)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment