Install jquery-file-upload assets for rails.
This commit is contained in:
@@ -3,7 +3,13 @@ class DocumentsController < ApplicationController
|
||||
before_filter :find_documentable, except: :destroy
|
||||
before_filter :prepare_new_document, only: :new
|
||||
before_filter :prepare_document_for_creation, only: :create
|
||||
load_and_authorize_resource
|
||||
|
||||
before_filter :validate_upload, only: :upload
|
||||
load_and_authorize_resource :except => [:upload]
|
||||
skip_authorization_check :only => [:upload]
|
||||
|
||||
def preload
|
||||
end
|
||||
|
||||
def new
|
||||
end
|
||||
@@ -27,6 +33,19 @@ class DocumentsController < ApplicationController
|
||||
redirect_to params[:from]
|
||||
end
|
||||
|
||||
def upload
|
||||
document = Document.new(documentable: @documentable, attachment: params[:file].tempfile, title: "faketitle", user: current_user )
|
||||
debugger
|
||||
# We only are intested in attachment validators. We set some fake data to get attachment errors only
|
||||
if document.valid?
|
||||
# TODO: Store file on tmp cache
|
||||
msg = { status: 200, msg: "OK" }
|
||||
else
|
||||
msg = { status: 422, msg: document.errors[:attachment].join(', ') }
|
||||
end
|
||||
render :json => msg
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_documentable
|
||||
@@ -47,4 +66,8 @@ class DocumentsController < ApplicationController
|
||||
params.require(:document).permit(:title, :documentable_type, :documentable_id, :attachment)
|
||||
end
|
||||
|
||||
def validate_upload
|
||||
if @documentable.present?
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user