Support file uploads

This allows submissions to store file uploads
This commit is contained in:
2020-04-09 11:02:07 +02:00
parent 73ccddee94
commit 10d80c6548
9 changed files with 107 additions and 14 deletions

View File

@@ -0,0 +1,8 @@
class FileUploadsController < ApplicationController
def show
@form = Form.find_by!(token: params[:form_id])
@submission = @form.submissions.find(params[:submission_id])
@file_upload = @submission.files_attachments.find(params[:id])
redirect_to url_for(@file_upload)
end
end

View File

@@ -5,14 +5,18 @@ class SubmissionsController < ApplicationController
def create
@form = Form.find_by!(token: params[:form_id])
@submission = @form.submissions.build(data: data_params)
# 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
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