【问题标题】:Table row tr not being interpreted by Slim and missing in HTML output表格行 tr 没有被 Slim 解释并且在 HTML 输出中丢失
【发布时间】:2014-04-25 23:56:29
【问题描述】:

我在我的 Rails 应用程序中使用 Slim,并且我的表格行 (tr) 没有在循环中被解释。

- if @item.suggestions.size > 0
  table
  - @item.suggestions.each do |suggestion|
    tr
      td=raw "<i>Posted by " + Shopper.find(suggestion.shopper_id).name + " at " + suggestion.created_at.to_formatted_s(:short) + ":</i>"
    tr
      td= suggestion.comment

这是它在浏览器中输出的内容:

当我在循环之外编写相同的表结构时(见下文),它工作正常。

table
  tr
    td "Table row 1"
  tr
    td "Table row 2"

【问题讨论】:

    标签: html ruby-on-rails slim-lang


    【解决方案1】:

    我更改了我的代码以使用与 Slim 示例代码 (https://github.com/slim-template/slim) 相同的约定,它解决了问题。

    - if @item.suggestions.any?
      table#suggestions
        - for suggestion in @item.suggestions
          tr
            td= suggestion.comment
          tr
            td=raw "<i>Posted by " + Shopper.find(suggestion.shopper_id).name + " at " + suggestion.created_at.to_formatted_s(:short) + ":</i>"
    

    【讨论】:

      猜你喜欢
      • 2016-05-30
      • 2012-09-06
      • 1970-01-01
      • 1970-01-01
      • 2021-08-20
      • 2021-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多