Kai Vong
Kai Vong

Reputation: 381

Escape forward slash in Ruby url helper

Setuping a staticMatic project using /index.html:

@slug = current_page.gsub(/\.html/, '')

returns "/index(.html)", but should be /index


Changing term corrects: - @slug = current_page.gsub("/", "").gsub(".html", "") as found in:

https://github.com/adamstac/staticmatic-bootstrap/blob/master/src/helpers/application_helper.rb

Upvotes: 1

Views: 1336

Answers (1)

ennuikiller
ennuikiller

Reputation: 46965

To delete the beginning "/" after you've stripped the html simply execute this (which will do both in one command):

current_page.gsub(/\.html/, '').gsub(/\//,''))

Upvotes: 1

Related Questions