Class: RailsRealtimeErd::AssetsController

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

Constant Summary collapse

ASSETS =
{
  "stimulus.js" => "app/javascript/rails_realtime_erd/vendor/stimulus.js",
  "mermaid.js" => "app/javascript/rails_realtime_erd/vendor/mermaid.js",
  "application.js" => "app/javascript/rails_realtime_erd/application.js"
}.freeze

Instance Method Summary collapse

Instance Method Details

#showObject



11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/rails_realtime_erd/assets_controller.rb', line 11

def show
  relative_path = ASSETS[params[:name]]
  return head :not_found unless relative_path

  path = Engine.root.join(relative_path)
  return head :not_found unless File.exist?(path)

  response.headers["Cache-Control"] = "private, max-age=300"
  response.headers["X-Content-Type-Options"] = "nosniff"
  send_file path, type: "text/javascript; charset=utf-8", disposition: "inline"
end