Class: Testimonials::MediaController

Inherits:
ApplicationController show all
Includes:
ActiveStorage::Streaming
Defined in:
app/controllers/testimonials/media_controller.rb

Overview

Hands out video and avatar files by testimonial id, so consumers never need to know about Active Storage. Admins can fetch anything; everyone else only reaches media of publishable (approved + consented) testimonials, and only when the read API is public. The actual bytes are streamed here after authorization. Keeping the browser on this route means an Active Storage URL cannot outlive the gate; Range support remains for video playback and seeking.

Instance Method Summary collapse

Instance Method Details

#avatarObject



29
30
31
32
33
# File 'app/controllers/testimonials/media_controller.rb', line 29

def avatar
  head :not_found and return unless @testimonial.avatar_attached?

  stream(@testimonial.avatar)
end

#posterObject



23
24
25
26
27
# File 'app/controllers/testimonials/media_controller.rb', line 23

def poster
  head :not_found and return unless @testimonial.poster_attached?

  stream(@testimonial.poster)
end

#videoObject



17
18
19
20
21
# File 'app/controllers/testimonials/media_controller.rb', line 17

def video
  head :not_found and return unless @testimonial.video_attached?

  stream(@testimonial.video_file)
end