38 lines
1.2 KiB
Ruby
38 lines
1.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
require 'google/apis/sheets_v4'
|
|
class SubmissionsController < ApplicationController
|
|
skip_before_action :verify_authenticity_token
|
|
wrap_parameters false
|
|
layout 'submission', only: [:create]
|
|
|
|
def create
|
|
@form = Form.find_by!(token: params[:form_id])
|
|
# create a new submission object. we need a persisted submission to be able to process
|
|
# potential the data - to be able to create URLs to uploads which is added as link to the table
|
|
@submission = @form.submissions.create(remote_ip: request.remote_ip, referrer: request.referer)
|
|
# processes the submitted data and saves the submission
|
|
@submission.process_data(data_params)
|
|
|
|
respond_to do |format|
|
|
if @submission.save
|
|
format.html do
|
|
redirect_to(@form.thank_you_url) if @form.thank_you_url.present?
|
|
end
|
|
format.json { render(json: { success: true, submission: @submission.data }) }
|
|
else
|
|
format.html do
|
|
redirect_to(@form.thank_you_url) if @form.thank_you_url.present?
|
|
end
|
|
format.json { render(json: { error: @submission.errors }, status: 422) }
|
|
end
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
def data_params
|
|
request.request_parameters
|
|
end
|
|
end
|