Created
November 14, 2012 20:37
-
-
Save brandon-beacher/4074622 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
def s3_upload_form_tag(bucket, subfolder = "uploads", presigned_post_options = {}, html_options = {}, &block) | |
key = [ | |
subfolder, | |
SecureRandom.urlsafe_base64, | |
'${filename}' ].reject(&:blank?).join('/') | |
s3 = AWS::S3.new | |
bucket = s3.buckets[bucket] | |
presigned_post = bucket.objects[key].presigned_post(presigned_post_options) | |
html_options[:action] = presigned_post.url.to_s | |
html_options[:enctype] = 'multipart/form-data' | |
html_options[:method] = 'post' | |
content_tag("form", html_options) do | |
presigned_post.fields.each do |name, value| | |
concat(hidden_field_tag(name, value)) | |
end | |
concat(capture(&block)) if block_given? | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StudentCsvUploadsController < ApplicationController | |
before_filter :authenticate_user! | |
layout :determine_layout | |
def new | |
@school = current_user.effective_affiliated_schools.find(params[:school_id]) | |
end | |
def show | |
@school = current_user.effective_affiliated_schools.find(params[:school_id]) | |
@student_csv_import = current_user.student_csv_imports.find_by_bucket_and_key(params[:bucket], params[:key]) | |
if @student_csv_import | |
redirect_to school_student_csv_imports_path(@school) | |
else | |
@student_csv_import = current_user.student_csv_imports.create!( | |
bucket: params[:bucket], | |
school: @school, | |
key: params[:key], | |
status: 'pending') | |
TTM::QC.enqueue_import("StudentCsvImporter.import", @student_csv_import.id) | |
redirect_to school_student_csv_imports_path(@school), notice: "File #{@student_csv_import.basename} has been uploaded and is queued for import." | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
h3 Step 3 | |
p Choose your template from where you saved it on your local computer by clicking on the 'Choose File' option below. Click 'Import'. | |
br | |
= s3_upload_form_tag S3_UPLOAD_FORM_BUCKET, 'student_csv_uploads', success_action_redirect: school_student_csv_upload_url(school) do | |
p= file_field_tag :file | |
hr | |
p= submit_tag "Import", class: "corebutton blue medium " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment