【问题标题】:Ignoring newlines in embedded ruby in haml忽略haml中嵌入的ruby中的换行符
【发布时间】:2013-07-14 01:28:15
【问题描述】:

我有一块很长的嵌入式红宝石,我不想放在一条线上。它远未完成,但它是这样开始的:

.office-img{:style => "background-image: url(#{image_path "http://placehold.it/219x250&text=Office"}",
            "data-lease-type" => office_listing.office_type)}

有没有办法做到这一点,这样我就可以换行来组织我的代码,而不会给我带来关于缩进等的错误?

【问题讨论】:

  • 您是否尝试过在行尾使用“\”(不带引号)?我不确定这是否可以让你打破缩进。

标签: ruby-on-rails haml


【解决方案1】:

查看section of the documentation for using more than one line

在像这样的元素属性的情况下,只要每个换行符直接在逗号之后,您就可以将它们分布在多行中(您给出的示例略有错误,可能会给您带来虚假错误 - 检查您的括号):

.office-img{:style => "background-image: url(#{image_path "http://placehold.it/219x250&text=Office"})",
            "data-lease-type" => office_listing.office_type}

【讨论】:

    猜你喜欢
    • 2011-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多