【问题标题】:Ruby on Rails 4 does not display content_tag :iRuby on Rails 4 不显示 content_tag :i
【发布时间】:2014-06-16 14:23:54
【问题描述】:

为什么除了 content_tag 之外的所有 content_tags 都显示:i

  def sign_full_tag(group, obj, name, input_type="text", size="12", popover=true)
    content_tag :div, class: "row" do
      content_tag :div, class: "col-md-" + size do
        content_tag :div, class: "form-group left-inner-addon" + class_for_invalid_input(obj, name) do
          content_tag(:i, "", class: "fa fa-user fa-fw text-muted") # NOT DISPLAY!!!
          group.text_field( name,
                            class: "form-control" + (popover ? " popover-add" : ""),
                            id: name.to_s.gsub("_", "-"),
                            type: input_type,
                            placeholder: "#{t('sign_up.placeholder.' + name.to_s)}",
                            data: { container: "body",
                                    toggle: "popover",
                                    placement: "bottom",
                                    content: (popover ?  "#{t('sign_up.popover.' + name.to_s)}" : nil) })

        end
      end
    end
  end

当我渲染这个助手时,我在浏览器中看不到标签“i”。 这应该如何工作?

【问题讨论】:

    标签: ruby-on-rails-4 helpers content-tag


    【解决方案1】:

    这是因为只返回块中的最后一条语句。您必须连接这两个语句,以便将其作为一个字符串返回:

    content_tag(:div, etc etc) do
      content_tag(:i, "") + group.text_field(name, etc etc)
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-21
      • 2015-03-03
      • 2014-09-02
      • 1970-01-01
      • 1970-01-01
      • 2012-11-24
      相关资源
      最近更新 更多