Class: RailsPulse::RouteHelper::RailsPulseHelper

Inherits:
Object
  • Object
show all
Defined in:
app/helpers/rails_pulse/route_helper.rb

Overview

Helper class to provide both routes and asset methods

Instance Method Summary collapse

Constructor Details

#initialize(view_context) ⇒ RailsPulseHelper

Returns a new instance of RailsPulseHelper.



11
12
13
# File 'app/helpers/rails_pulse/route_helper.rb', line 11

def initialize(view_context)
  @view_context = view_context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Delegate route methods to engine routes



16
17
18
19
20
21
22
# File 'app/helpers/rails_pulse/route_helper.rb', line 16

def method_missing(method, *args, &block)
  if RailsPulse::Engine.routes.url_helpers.respond_to?(method)
    RailsPulse::Engine.routes.url_helpers.send(method, *args, &block)
  else
    super
  end
end

Instance Method Details

#asset_path(asset_name) ⇒ Object

Generate asset paths using Rails asset pipeline This allows assets to work with CDN, digests, and precompiled manifests



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/helpers/rails_pulse/route_helper.rb', line 30

def asset_path(asset_name)
  # Only use asset pipeline if we have Sprockets/Propshaft configured
  # Otherwise fall back to middleware serving
  if defined?(::Sprockets) || defined?(::Propshaft)
    # Use the main application's asset_path helper to ensure we get
    # the correct digested paths from the precompiled manifest
    begin
      ActionController::Base.helpers.asset_path(asset_name)
    rescue => e
      # Fallback to direct path if asset pipeline is not available
      Rails.logger.warn "[Rails Pulse] Asset pipeline error for #{asset_name}: #{e.message}"
      "/rails-pulse-assets/#{asset_name}"
    end
  else
    # No asset pipeline - use middleware serving
    "/rails-pulse-assets/#{asset_name}"
  end
end

#respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/helpers/rails_pulse/route_helper.rb', line 24

def respond_to_missing?(method, include_private = false)
  RailsPulse::Engine.routes.url_helpers.respond_to?(method, include_private) || super
end