From d581b07e9f4b950f1aeef315f59e913e040bd2cb Mon Sep 17 00:00:00 2001 From: Matt Menefee Date: Wed, 8 Jan 2025 17:06:18 -0600 Subject: [PATCH] Prevent `asset_path` clashing with route definition in a Rails app If a Rails app has `resources :assets` configured in `config/routes.rb` and the `config.assets.prefix` setting configured in `config/initializers/assets.rb` to something other than `assets`, use of `asset_path` to locate the `hotwire_spark.js` file will result in an error and the file not being found. Rails provides a solution for this by aliasing `asset_path` with `path_to_asset`. --- lib/hotwire/spark/middleware.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hotwire/spark/middleware.rb b/lib/hotwire/spark/middleware.rb index 5e31d4e..f1ebe44 100644 --- a/lib/hotwire/spark/middleware.rb +++ b/lib/hotwire/spark/middleware.rb @@ -39,7 +39,7 @@ def inject_javascript(html) end def script_tag - script_path = view_helpers.asset_path("hotwire_spark.js") + script_path = view_helpers.path_to_asset("hotwire_spark.js") view_helpers.javascript_include_tag(script_path) end