Class: Testimonials::NpsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/testimonials/nps_controller.rb', line 12

def create
  nps = NpsResponse.new(nps_params)
  nps.locale = I18n.locale.to_s
  nps.user_agent = request.user_agent
  attribute_author(nps)

  if nps.save
    PromptEvent.record!(kind: 'nps', action: 'submitted',
                        author_id: current_author_id, visitor_token: ensure_visitor_token)
    notify_host(nps)
    notify_detractor(nps) if nps.detractor?
    render json: { offer_testimonial: offer_testimonial?(nps) }, status: :created
  else
    render json: { errors: nps.errors.full_messages }, status: :unprocessable_entity
  end
end