Advertisement
guiil

uploads_controller.rb

Feb 22nd, 2017
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rails 0.70 KB | None | 0 0
  1. class UploadsController < ApplicationController
  2.   def index
  3.     @upload = Upload.new
  4.   end
  5.  
  6.   def create
  7.     @upload = Upload.new(upload_params)
  8.     if @upload.save
  9.       render json: { message: "success", uploadId: @upload.id }, status: 200
  10.     else
  11.       render json: { error: @upload.errors.full_messages.join(", ") }, status: 400
  12.     end
  13.   end
  14.  
  15.   def destroy
  16.     @upload = Upload.find(params[:id])
  17.     if @upload.destroy
  18.       render json: { message: "file deleted from server" }
  19.     else
  20.       render json: { message: @document.errors.full_messages.join(", ") }
  21.     end
  22.   end
  23.  
  24.   private
  25.     def upload_params
  26.       params.require(:upload).permit(:name, :email, :document)
  27.     end
  28. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement