Skip to content

Instantly share code, notes, and snippets.

@thattimc
Created July 5, 2015 05:08
Show Gist options
  • Save thattimc/cc1df515853446770035 to your computer and use it in GitHub Desktop.
Save thattimc/cc1df515853446770035 to your computer and use it in GitHub Desktop.
Embedded SVG to Rails
def embedded_svg(filename, options = {})
assets = Rails.application.assets
file = assets.find_asset(filename).body.force_encoding("UTF-8")
doc = Nokogiri::HTML::DocumentFragment.parse file
svg = doc.at_css "svg"
if options[:class].present?
svg["class"] = options[:class]
end
raw doc
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment