Skip to content

Commit

Permalink
Prevent asset_path clashing with route definition in a Rails app
Browse files Browse the repository at this point in the history
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`.

Co-authored-by: Matt Menefee <[email protected]>
  • Loading branch information
jorgemanrubia and mattmenefee committed Jan 25, 2025
1 parent 94b9278 commit a521664
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/hotwire/spark/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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, defer: "")
end

Expand Down

0 comments on commit a521664

Please sign in to comment.