Class: Testimonials::SubmissionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/testimonials/submissions_controller.rb

Overview

The widget's write endpoint: POST to the mount path.

Public, so it stays on ApplicationController and never inherits a host's admin base controller — a member leaving a review must not be asked for a staff session. The dashboard's read/triage actions live in TestimonialsController, which does inherit it.

Instance Method Summary collapse

Instance Method Details

#createObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'app/controllers/testimonials/submissions_controller.rb', line 21

def create
  testimonial = build_testimonial

  error = attach_video(testimonial) || attach_avatar(testimonial)
  return render json: { errors: [error] }, status: :unprocessable_entity if error

  if testimonial.save
    # Purge only after a valid save, so a failed update can't strand a
    # review with its video already gone.
    if remove_video? && testimonial.video_attached?
      testimonial.video_file.purge
      testimonial.poster.purge if testimonial.poster_attached?
    end
    record_submission
    notify_host(testimonial)
    head :created
  else
    render json: { errors: testimonial.errors.full_messages }, status: :unprocessable_entity
  end
end