简体   繁体   English

如何使用haml与Rails中的许多元素建立链接

[英]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. 缩进不一致:缩进使用了“ \\ t \\ t \\ t \\ t \\ t”,但是文档的其余部分使用1个制表符进行了缩进。

The error line number it's the first line after link_to; 错误行号是link_to之后的第一行; the %span element. %span元素。 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. 因此,我认为这是因为我没有以正确的方式使用link_to,但是看到该错误涉及缩进问题,并且在以多种不同方式尝试后,我无法使其运行。

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. 这将摆脱任何时髦的生意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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