【问题标题】:rails ignoring content tag [duplicate]rails忽略内容标签[重复]
【发布时间】:2020-02-10 12:04:26
【问题描述】:

我的一个助手中有以下代码:

  def send_fragments_to_other_template(template, counter)
    if counter == 0
      content_tag "div", class: "card w-5c" do
        content_tag "div", class: "card__content resource" do
          content_tag "h4" do
            content_tag "span", "Send fragments to other template"
          end
          link_to "Send", edit_admin_template_fragment_path(template), class: "btn btn--s-purple", remote: true
        end
      end
    end
  end

问题出在这里:无论出于何种原因,rails 都忽略了第三个和第四个内容标签。我在页面上有两个 div 和按钮(锚点),但没有 h4 或 span。

我做错了什么?

【问题讨论】:

    标签: ruby-on-rails ruby helper content-tag


    【解决方案1】:

    看起来类似于堆栈溢出的这篇文章:Why does this nested content_tag not render properly? 这里发生的是 content_tag 只呈现 do-end 块中的最后一个表达式。这可能就是为什么您可以看到“发送”按钮而不是其他按钮的原因。 我更喜欢使用行为类似于 puts 的 concat 来解决这个问题。这是上面帖子中的第二个答案^。

    【讨论】:

    • 非常感谢,辛杜!这个答案是对的,我需要一个连接。感谢您将我指向正确的帖子,下次我会在发布之前搜索更多内容。
    猜你喜欢
    • 1970-01-01
    • 2010-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-12
    • 2015-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多