How do I display SVG image in Rails?

后端 未结 7 2081
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-04 16:45

I have a svg image on /app/asssets/images/symbols.svg with this as contents.



        
7条回答
  •  北荒
    北荒 (楼主)
    2021-01-04 17:39

    Create a helper: (content is different in each case, custom your own one)

    def icon(icon, css_class: "")
      content_tag(:svg, class: "icon icon_#{icon} #{css_class}") do
          content_tag(:use, nil, 'xlink:href' => "#icon_#{icon}")
      end
    end
    

    Use it like this:

    <%= icon 'arrow-menu' , css_class: 'arrow-breadcrumb' %>
    

提交回复
热议问题