I have a problem with removing everything after the last slash of URL in Elixir. For instance, I have URL:
http://localhost:4000/admins/new
I wanna change it to:
http://localhost:4000/admins
How can I do it?
The safest way would probably be to use URI.parse/1
uri = URI.parse("http://localhost:4000/admins/new")
%URI{uri |
path:
uri.path
|> String.split("/")
|> Enum.slice(0..-2)
|> Enum.join("/")
}
|> URI.to_string()
#⇒ "http://localhost:4000/admins"