From c7da2f24d54570e05db188c1054930ff0c659e72 Mon Sep 17 00:00:00 2001 From: Vladimir Dementyev Date: Sat, 12 Dec 2020 19:21:36 +0300 Subject: [PATCH] Fix asset path for Rails (#268) The path to assets should be consistent and not depend on the current script source. There are at least two situations when this assumption fails: - When running `webpacker-dev-server`, the _pack_ URL doesn't contain `/js/` part. - In test environment, `/packs-test` is used by default. --- docs/tutorials/integrating-with-rails.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/tutorials/integrating-with-rails.md b/docs/tutorials/integrating-with-rails.md index 890e4f79..87f069e8 100644 --- a/docs/tutorials/integrating-with-rails.md +++ b/docs/tutorials/integrating-with-rails.md @@ -36,8 +36,13 @@ import { defineCustomElements, setAssetPath } from '@shoelace-style/shoelace' // ... +const rootUrl = document.currentScript.src.replace(/\/packs.*$/, '') + +// Path to the assets folder (should be independent on the current script source path +// to work correctly in different environments) +setAssetPath(rootUrl + '/packs/js/') + // This enables all web components for the current page -setAssetPath(document.currentScript.src) defineCustomElements() ```