Jngai1297 Jngai1297 - 1 year ago 74
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 %>"

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

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

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

ndn ndn
Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download