Links do not work after translation into slim form

2019-08-24 06:50发布

问题:

I have an html code with rails. I need to translate it into slim format, I changed the file format, translated it with a convector and tried to run it as a result the links do not work, can you tell me why?

head.html.erb

<section id="header">
  <div class='navigation-panel'>
    <button class='burger-button' id='header-burger-button container'  onclick='burgerAction()'>
      <%= image_tag("header/burger.png") %>
    </button>
    <button class='contact-us-button burger-hidable container' onclick='scroller("contact")'> CONTACT US </button>
    <div class='menu-container burger-hidable container' style='display: none;'>
      <%= image_tag("header/menu.png") %>
    </div>
    <div class='nav-links burger-hidable' style='display: none;'>
      <p onclick='scroller("header")'>Home</p>
      <p onclick='scroller("services")'>Services</p>
      <p onclick='scroller("how-we-work")'>How We Work</p>
      <p onclick='scroller("team")'>Team</p>
      <p onclick='scroller("why-us")'>Why Us</p>
      <p onclick='scroller("portfolio")'>Portfolio</p>
      <p onclick='scroller("contact")'>Contact Us</p>
    </div>
  </div>
</section>

head.html.slim

section#header
  .navigation-panel
    button.burger-button id=("header-burger-button container") onclick="burgerAction()" 
      = image_tag("header/burger.png")
    button.contact-us-button.burger-hidable.container onclick="scroller(\"contact\")"  CONTACT US
    .menu-container.burger-hidable.container style=("display: none;") 
      = image_tag("header/menu.png")
    .nav-links.burger-hidable style=("display: none;") 
      p onclick="scroller(\"header\")"  Home
      p onclick="scroller(\"services\")"  Services
      p onclick="scroller(\"how-we-work\")"  How We Work
      p onclick="scroller(\"team\")"  Team
      p onclick="scroller(\"why-us\")"  Why Us
      p onclick="scroller(\"portfolio\")"  Portfolio
      p onclick="scroller(\"contact\")"  Contact Us

回答1:

I believe the problem is the escaped quotation inside the onclick attributes.

Consider using single quotes inside your attributes' double quotes: onclick="scroller('header')".

You can read more about escaping and quoting attributes here: https://www.rubydoc.info/gems/slim/frames#Output_without_HTML_escaping___