Skip to content

Instantly share code, notes, and snippets.

@josepmartins
Last active January 29, 2023 18:19
Show Gist options
  • Save josepmartins/7091420d90300870f347 to your computer and use it in GitHub Desktop.
Save josepmartins/7091420d90300870f347 to your computer and use it in GitHub Desktop.
SVG inline helpers for Rails
# Inline svg from @tomeara https://gist.github.com/tomeara/6515860
def inline_svg(path)
file = File.open("app/assets/images/#{path}", "rb")
raw file.read
end
# Use SVG internal link
def use_svg(clazz)
content_tag(:svg, content_tag(:use, "", { "xlink:href" => '#icon-' + clazz }), class: "icon icon-#{clazz}")
end
# Render defs just after body tag
# = inline_svg('icons/svgdefs.svg')
# SVG internal link
#= use_svg('bell')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment