3

I'm working on a Ruby on Rails app that is using Webpacker. I get a strange undefined method error when using asset_pack_path - a NoMethodError is thrown and says undefined method 'asset_path' Did you mean? asset_pack_path. This is a similarly named method but not the one I am calling; asset_path does not appear in the app's codebase either.

I believe to be calling the correct path inside of asset_pack_path but that does not seem to be consistent with the error. Perhaps there is a versioning mis-match somewhere? I am at a loss with this one. Any ideas or suggestions to resolve this undefined method error and use asset_pack_path would be helpful. Thanks!

enter image description here

2 Answers 2

3

You are trying to call Rails Views helper method inside a Controller.

Try: ActionController::Base.helpers.asset_pack_path

Sign up to request clarification or add additional context in comments.

1 Comment

No idea why, but I needed ActionController::Base.helpers.asset_pack_path("media/images/logo.png") - it refused to work for me without the media/images/ part, even though logo.png was inside images/, not in any special place. I figured out what it wanted by running bin/webpack in the terminal and looking at the output. Hope it helps someone.
3

It turned out that asset_path was called inside the asset_pack_path method - both ActionView::Helpers::AssetUrlHelper Webpacker::Helper need to be included for asset_pack_path to work

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.