Class: RailsPulse::AssetsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/rails_pulse/assets_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#set_global_filters, #set_pagination_limit

Instance Method Details

#showObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/rails_pulse/assets_controller.rb', line 5

def show
  asset_name = params[:asset_name]
  asset_path = Rails.root.join("public", "rails-pulse-assets", asset_name)

  # Fallback to engine assets if not found in host app
  unless File.exist?(asset_path)
    asset_path = RailsPulse::Engine.root.join("public", "rails-pulse-assets", asset_name)
  end

  if File.exist?(asset_path)
    content_type = case File.extname(asset_name)
    when ".js" then "application/javascript"
    when ".css" then "text/css"
    when ".map" then "application/json"
    when ".svg" then "image/svg+xml"
    else "application/octet-stream"
    end

    send_file asset_path,
              type: content_type,
              disposition: "inline",
              cache: true,
              expires: 1.year.from_now
  else
    head :not_found
  end
end