Skip to content
New issue

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

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

Already on GitHub? # to your account

Added new method to check if path starts with media or add it #100

Closed

Conversation

damjack
Copy link

@damjack damjack commented Jul 19, 2019

At this time the Webpacker.manifest.lookup check the correct path of the file. If you not specify the path prepended with media, the Webpacker return nil.

I've added a new method to check if the filename starts with media, otherwise add it.

Copy link
Owner

@jamesmartin jamesmartin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for opening this PR! ✨

Would you mind adding a test for your change?

@jamesmartin jamesmartin mentioned this pull request Jan 27, 2020
Base automatically changed from master to main September 1, 2020 23:10
@clinejj
Copy link

clinejj commented Mar 24, 2021

From the discussion on #109, should the behavior be updated to match image_pack_tag?
https://github.com/rails/webpacker/blob/4565b843f649842b03c99fd877e6f3681dd92027/lib/webpacker/helper.rb#L149-L154

def resolve_path_to_image(name, **options)
  path = name.starts_with?("media/images/") ? name : "media/images/#{name}"
  path_to_asset(current_webpacker_instance.manifest.lookup!(path), options)
rescue
  path_to_asset(current_webpacker_instance.manifest.lookup!(name), options)
end

Essentially rather than just looking for media, check instead for media/images?

@jamesmartin
Copy link
Owner

rather than just looking for media, check instead for media/images?

@clinejj thanks for the suggestion. I don't have a strong opinion on this one, as I don't really use Webpacker in any projects currently. I'm happy to defer to others on this. 🤷

@andi-dev
Copy link

Just wanted to mention, that image_pack_tag uses the "static/" prefix now, and not "media/images": https://github.com/rails/webpacker/blob/master/lib/webpacker/helper.rb#L156

@jamesmartin jamesmartin deleted the branch jamesmartin:main September 30, 2024 07:31
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants