Ruby on Rails 4 does not display content_tag :i

瘦欲@ 提交于 2021-02-08 04:31:48

问题


Why are all the content_tags display except the content_tag :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

When I render this helper I don't see tag "i" in my browser. How should this work?


回答1:


That is because only the last statement in a block is returned. You have to concat the two statements so it is returned as one string:

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


来源:https://stackoverflow.com/questions/24245922/ruby-on-rails-4-does-not-display-content-tag-i

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!