Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't find assets in production if '.svg' is forgotten #41

Closed
hansottowirtz opened this issue Jul 12, 2016 · 6 comments
Closed

Can't find assets in production if '.svg' is forgotten #41

hansottowirtz opened this issue Jul 12, 2016 · 6 comments
Milestone

Comments

@hansottowirtz
Copy link

So inline_svg 'logo' works in development, but not in production. inline_svg 'logo.svg' works in both. I think InlineSvg::AssetFile should append .svg if it is not present, or raise an Error.

filename = "#{filename}.svg" unless filename.end_with?('.svg')

It is very confusing if this problem occurs.

@jamesmartin
Copy link
Owner

inline_svg always tries to use Sprockets to dynamically find files. The Sprockets asset finder is pretty lenient, allowing you to leave off the file extension. If you disable Sprockets in production and instead opt to serve precompiled assets (as many people do, for performance reasons), then we fall back to a naive asset finder, which simply looks in the #{Rails.root.join("public")} directory for the exact filename.

We could update the naive asset finder to append .svg if it's not present. The reason we don't raise an error when a file is not found is to mirror Rails' built-in image tag helpers, which will simply render the <img ... /> tag regardless if the file exists. You should see a HTML comment in your rendered page that tells you the SVG file could not be found.

@hansottowirtz
Copy link
Author

Didn't know that, very interesting! I think it's indeed a good idea to mirror the image_tag helpers. Maybe we could try clarifying the error message:

if filename.ends_with? '.svg'
  "<svg><!-- SVG file not found: '#{filename}' --></svg>"
else
  "<svg><!-- SVG file not found: '#{filename}' (Try adding '.svg' to your filename) --></svg>"
end

@jamesmartin
Copy link
Owner

Maybe we could try clarifying the error message

Good idea. We could add that hint if we're using the naive asset finder and not Sprockets.

@jamesmartin
Copy link
Owner

Fixed in v0.9.1.

@jamesmartin jamesmartin modified the milestones: 0.10.0, 0.9.1 Jul 18, 2016
@madeindjs
Copy link

I discovered this issue in production environment. Why not simply put .svg extension when not present?

@jamesmartin
Copy link
Owner

Why not simply put .svg extension when not present?

@madeindjs the reason I chose to add the empty <svg> tag is to match the behavior of Rails' built in helpers like image_tag, which don't care if the file specified exists, it just renders the <img> tag. I felt this would be more consistent and approachable to Rails developers. We added the extension "hint" as a convenience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants