سؤال

I am trying to follow this guide: http://css-tricks.com/svg-sprites-use-better-icon-fonts

Chris states to inject the svg just after the opening body tag. In PHP this is simple but i'm using Rails so have an .html.erb file.

How do I include the file using this? I have tried asset helpers, evaluate, render. Nothing seems to work?

هل كانت مفيدة؟

المحلول

This belongs to Ruby Racer.

inline_svg_helper.rb

def inline_svg(path)
    File.open("app/assets/images/#{path}", "rb") do |file|
    raw file.read
  end
end

نصائح أخرى

<%= image_tag 'file.svg' %> didn't seem to work on Chrome browser, so I tried render to include svg file in following way, and it worked to me.

<%= render inline: (render file: Rails.root.join('app', 'assets', 'images', 'file.svg')) %>

And I have another question, is it a good (or safe) way?

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top