Skip to content

Instantly share code, notes, and snippets.

@izszzz
Last active July 7, 2022 13:17
Show Gist options
  • Save izszzz/abeec39712a8908f50278df17590b942 to your computer and use it in GitHub Desktop.
Save izszzz/abeec39712a8908f50278df17590b942 to your computer and use it in GitHub Desktop.
svg_use_tag

Rails View use tag

Description

  1. instllation svg file

app/assets/images/svg/icon-filename.svg

  1. edit svg file

add attribute id for svg tag id == filename

<svg id="icon-filenam"></svg>
  1. use
= svg_use_tag "icon-filename"
def svg_use_tag(name, **attributes)
path = asset_path("svg/#{name}.svg")
tag.svg **attributes do
tag.use "xlink:href": "#{path}##{name}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment