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

Undefined method find_asset #97

Closed
guillaumewrobel opened this issue Jun 17, 2019 · 9 comments
Closed

Undefined method find_asset #97

guillaumewrobel opened this issue Jun 17, 2019 · 9 comments

Comments

@guillaumewrobel
Copy link

guillaumewrobel commented Jun 17, 2019

Hello,

Just upgraded gem from 1.4.0 to 1.5.0 and this error came in production. Nothing changed on my side:

html

<div>
  <%= inline_svg("logo.svg") %>
</div>

error

ActionView::Template::Error undefined method `find_asset` for nil:NilClass

Probably linked to the webpack code.

Happy to help if you need more info.

@organicweb
Copy link

Same problem here, no update but error message :

HTML :

- cache 'main--nav-socials' do
  = link_to root_path, class: %w(navbar-brand) do
    %span.sr-only Lorem ipsum
    = inline_svg 'logo.svg', height: '30px'

Error :

ActionView::Template::Error (undefined method find_asset' for nil:NilClass):`

@bjeanes
Copy link

bjeanes commented Jun 18, 2019

Same problem. It looks like adding Webpacker support may have implicitly broken the gem for people who do not have webpacker installed.

@jamesmartin
Copy link
Owner

jamesmartin commented Jun 18, 2019

@guillaumewrobel thanks for opening this issue and sorry about the error. Could you tell me:

  • Which version of Rails are you using?
  • Are you using Webpack at all?
  • Are you using Sprockets or Webpacker? Or both?
  • Are you using your own custom asset_finder?
  • Could you paste your InlineSvg.configure block, if any

You mentioned that you're seeing this in production. Is it reproducible in development also?

(P.S. anybody else on this thread experiencing this problem, please feel free to also answer these questions)

Same problem. It looks like adding Webpacker support may have implicitly broken the gem for people who do not have webpacker installed.

When Webpacker is not installed the gem should try to use Sprockets by default and fallback to the naive StaticAssetFinder if that can't be found.

@bgmat
Copy link

bgmat commented Jun 18, 2019

The same error for me too.
Using rails 5.2.3 on heroku (no webpack, no custom asset_finder).
I downgraded to version 1.4.0

@jamesmartin
Copy link
Owner

Thanks for the information, @bgmat. I was able to reproduce this on a test Heroku app. I've shipped a fixed version that falls back to the static asset finder (4c0da9e) in v1.5.1. Please give it a try and let me know if it doesn't fix the problem for you.

Sorry for the trouble, everybody. The gem has decent test coverage, but the failure in this case was (of course) in the one untested part: The Railtie. This has remained largely untested because it's kind of painful to test a Railtie in a gem (all the Rails dependencies). I've started looking into lightweight ways to unit test Railties without requiring all of Rails so I can hopefully prevent this class of problem in future.

@guillaumewrobel
Copy link
Author

same config as @bgmat

Rails 5.2.3 on Heroku
No webpack
No custom asset_finder
No InlineSvg config

@jamesmartin
Copy link
Owner

@guillaumewrobel thanks for the info. Please try bundle update inline_svg and give v1.5.1 a try. I think that should fix your problem. If not, please let me know.

@guillaumewrobel
Copy link
Author

1.5.1 version works! Thank you for the quick answer & fix @jamesmartin

@organicweb
Copy link

organicweb commented Jun 18, 2019

Sorry for late response

No webpack
Rails 4.2.11.1
Ruby 2.5.5 or Ruby 2.5.0
My own hosting
No custom asset_finder
No InlineSvg config

I'll give a try this week to 1.5.1

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

No branches or pull requests

5 participants