1

I have an SVG file that's part of a template located at:

vendor/theme/assets/icons/icon-1.svg

How do I render that inline in my view? render partial: path fails and says it can't find a partial.

Amin Shah Gilani
  • 8,675
  • 5
  • 37
  • 79

1 Answers1

0

In your view insert the following:

<%= render inline: Rails.root.join('vendor/theme/assets/icons/icon-1.svg').read %>

If you're going to be doing this multiple times, you may want to refactor this into a helper.

Also, think about the following:

  • Are you okay with dumping third party code directly into your view?
  • Is the vendor SVG file updated automatically without review?
  • Are you sure the vendor SVG file will never contain malicious code?
Amin Shah Gilani
  • 8,675
  • 5
  • 37
  • 79