rubyurihamlstaticmatic

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


Solution

  • 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(/\//,''))