Class: S3UploadsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- S3UploadsController
- Defined in:
- lib/generators/s3_cors_fileupload/install/templates/s3_uploads_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /source_files POST /source_files.json.
-
#destroy ⇒ Object
DELETE /source_files/1 DELETE /source_files/1.json.
-
#generate_key ⇒ Object
used for s3_uploader.
-
#index ⇒ Object
GET /source_files GET /source_files.json.
Instance Method Details
#create ⇒ Object
POST /source_files POST /source_files.json
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/generators/s3_cors_fileupload/install/templates/s3_uploads_controller.rb', line 15 def create @source_file = SourceFile.new(params[:source_file]) respond_to do |format| if @source_file.save format.html { render :json => @source_file.to_jq_upload, :content_type => 'text/html', :layout => false } format.json { render json: @source_file.to_jq_upload, status: :created } else format.html { render action: "new" } format.json { render json: @source_file.errors, status: :unprocessable_entity } end end end |
#destroy ⇒ Object
DELETE /source_files/1 DELETE /source_files/1.json
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/generators/s3_cors_fileupload/install/templates/s3_uploads_controller.rb', line 34 def destroy @source_file = SourceFile.find(params[:id]) @source_file.destroy respond_to do |format| format.html { redirect_to source_files_url } format.json { head :no_content } format.xml { head :no_content } end end |
#generate_key ⇒ Object
used for s3_uploader
46 47 48 49 50 51 52 53 |
# File 'lib/generators/s3_cors_fileupload/install/templates/s3_uploads_controller.rb', line 46 def generate_key uid = SecureRandom.uuid.gsub(/-/,'') render json: { key: "uploads/#{uid}/#{params[:filename]}", success_action_redirect: "/" } end |
#index ⇒ Object
GET /source_files GET /source_files.json
4 5 6 7 8 9 10 11 |
# File 'lib/generators/s3_cors_fileupload/install/templates/s3_uploads_controller.rb', line 4 def index @source_files = SourceFile.all respond_to do |format| format.html # index.html.erb format.json { render json: @source_files.map{|sf| sf.to_jq_upload } } end end |