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

Not working without sprockets #95

Closed
askehansen opened this issue Jun 12, 2019 · 5 comments
Closed

Not working without sprockets #95

askehansen opened this issue Jun 12, 2019 · 5 comments

Comments

@askehansen
Copy link

When using this in a new rails 6 app i get the error:
undefined method 'assets' for #<Rails::Application::Configuration:0x00007ffba1c234f0>

I guess it fails here because rails 6 now uses webpacker instead of sprockets:

if ::Rails.application.config.assets.compile

@jamesmartin
Copy link
Owner

@askehansen thanks for opening this issue. 👍

I guess it fails here because rails 6 now uses webpacker instead of sprockets:

That seems the most likely cause of the problem. I haven't had a chance to try this gem with a vanilla Rails 6 project yet. I'll put this on my todo list.

@jamesmartin
Copy link
Owner

jamesmartin commented Jun 14, 2019

Just tested by upgrading a Rails 5.2 app to Rails 6.0.0.rc1: inline_svg still works with Rails 6 if you use Sprockets.

I'll have to figure out what's needed to make it work with Webpacker.

@askehansen
Copy link
Author

askehansen commented Jun 14, 2019

Okay so I just noticed I had --skip-sprockets in my ~/.railsrc file.
That means this issue is not regarding rails 6, but an issue if you disable sprockets and use webpacker in favor of sprockets. Sorry for the confusion!

However I would like to contribute in making this gem not relying on sprockets.

What is the disadvantage of doing this instead?

class StaticAssetFinder
...

  def pathname
    Rails.root.join('assets', @filename)
  end
end

@askehansen askehansen changed the title Incompatible with rails 6 Not working without sprockets Jun 14, 2019
@askehansen
Copy link
Author

I realized I can write my own asset file loader and just use that instead:

class BasicAssetFileLoader
  def self.named(filename)
    File.open("app/assets/#{filename}", "rb") do |file|
      file.read
    end
  end
end

InlineSvg.configure do |config|
  config.asset_file = BasicAssetFileLoader
end

Again, sorry for the confusion and not reading the documentation!
And thanks for a great gem! 😊👍

@jamesmartin
Copy link
Owner

Added support for Webpacker in v1.5.0

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

2 participants