简体   繁体   中英

How to make a link with many elements in rails using haml

I am very new in ruby, in rails and in haml. I was recoding a little site I have, and I was trying to create a link in wich is nested a few elements.

The structure I want to be outputted is this one:

<a href="somewhere">
    <span>
         <img src="/imgs/hello.png" />
    </span>
    <strong>6
        <em>Oct</em>
    </strong>
    <h1>Title</h1>
</a>

So I was trying it doing this (obviously its real indentation is one tab more than the parent element):

= link_to("somewhere") do 
    %span
        %img(src="/imgs/hello.png")
    %strong 6
        %em Oct
    %h1 Title
end

Wich for me seems to be logic. But it does not. It gives me this error:

Inconsistent indentation: " \\t\\t\\t\\t\\t" was used for indentation, but the rest of the document was indented using 1 tab.

The error line number it's the first line after link_to; the %span element. So, I thought it was because I was not using link_to in a correct way, but seeing that the error talks about indentation problems and after trying it in many different ways, I cannot get it into run.

This should work.

= link_to("somewhere") do
  %span
    %img(src="/imgs/hello.png")
    %strong 
      6
      %em Oct
  %h1 Title

Also, make sure in your editor you're using spaces as tabs. This will get rid of any funky business.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM