代码之家  ›  专栏  ›  技术社区  ›  kaichanvong

Ruby url助手中的转义正斜杠

  •  1
  • kaichanvong  · 技术社区  · 14 年前

    使用设置staticMatic项目 /index.html :

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

    "/index(.html)" ,但应该是 /index


    @slug = current_page.gsub("/", "").gsub(".html", "") 见:

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

    1 回复  |  直到 6 年前
        1
  •  1
  •   ennuikiller    14 年前

    要在剥离html后删除开头“/”,只需执行以下命令(这将在一个命令中同时执行):

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