inline_svg icon indicating copy to clipboard operation
inline_svg copied to clipboard

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

Open damjack opened this issue 6 years ago • 3 comments

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.

damjack avatar Jul 19 '19 09:07 damjack

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?

clinejj avatar Mar 24 '21 15:03 clinejj

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. 🤷

jamesmartin avatar Mar 25 '21 06:03 jamesmartin

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

andi-dev avatar Jun 10 '22 11:06 andi-dev