Sam Roberts Sam Roberts - 4 years ago 121
Javascript Question

Remove trailing '/' from rails string

So i have this command at the moment, ITs breaking up a URL to get the ID from said URL

The URL has a forward slash on the end. Which is currently bringing in the ID like this


I need to remove the forward slash on the end so its like

Heres what i have at the moment

var apis = '<%= @event.slink.split('-')[-1] %>';

I have currently already tried putting .gsub on the end however that didnt work (I may have not done this right however)


Answer Source


var apis = '<%= @event.slink.split('-')[-1].gsub(/\/$/, '') %>';
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download