Jngai1297 Jngai1297 - 5 months ago 23
Ruby Question

How to replace the last "/" with a dash in a URL

I have this URL in a Sinatra-based application:

<li><a href="/blog/<%= blog.title.tr(' ', '-') %>/<%= blog.slug %>"
method="get">Show</a></li>


When I click on it, the URL looks like this:

http://127.0.0.1:9292/blog/A-lovely-day/654790


I am trying to make the last
/
also a
-
too, so it will be:

http://127.0.0.1:9292/blog/A-lovely-day-654790


How do I replace it after the URL has been rendered?

ndn ndn
Answer

Given that you started with:

original url generation with colors

The slash is not part of the title, but simply the character in red. Replace it with - in the code:

url generation with slash replace with dash