Support file uploads
This allows submissions to store file uploads
This commit is contained in:
8
app/controllers/file_uploads_controller.rb
Normal file
8
app/controllers/file_uploads_controller.rb
Normal 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
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user