Skip to content

Commit

Permalink
Use view_helpers of the controller instance instead of standalone module
Browse files Browse the repository at this point in the history
Fixes #43
  • Loading branch information
codergeek121 committed Dec 23, 2024
1 parent a5ac411 commit b08301d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/hotwire/spark/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def call(env)
status, headers, response = @app.call(env)

if html_response?(headers)
@request = ActionDispatch::Request.new(env)
html = html_from(response)
html = inject_javascript(html)
html = inject_options(html)
Expand Down Expand Up @@ -38,7 +39,7 @@ def script_tag
end

def view_helpers
ActionController::Base.helpers
@request.controller_instance.helpers
end

def inject_options(html)
Expand Down
2 changes: 2 additions & 0 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,7 @@ class Application < Rails::Application
#
# config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras")

config.asset_host = ->(asset, request) { "#{request.host}:#{request.port}" }
end
end

0 comments on commit b08301d

Please sign in to comment.