tinyforms/app/controllers/submissions_controller.rb
Michael Bumann 10d80c6548 Support file uploads
This allows submissions to store file uploads
2020-04-09 11:02:07 +02:00

31 lines
1.1 KiB
Ruby

require 'google/apis/sheets_v4'
class SubmissionsController < ApplicationController
skip_before_action :verify_authenticity_token
wrap_parameters false
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 { redirect_to(@form.thank_you_url) if @form.thank_you_url.present? }
format.json { render(json: { success: true, data: @submission.data }) }
else
format.html { redirect_to(@form.thank_you_url) if @form.thank_you_url.present? }
format.json { render(json: { error: @submission.errors }, status: 422) }
end
end
end
private
def data_params
request.request_parameters
end
end