Accurate Rails Form Loader

I recently installed Fine Uploader in our Rails application. I read the documentation and experimented a bit with it, but I do not seem to understand how this actually works, and because of this I have a lot of problems with its implementation.

What I did: Installed it (two ways, one is “classic” and the other using a fineuploader flashlight, which seems to do the same).

Created a coffee file containing this.

$ ->
  uploader = new (qq.FineUploader)(
    debug: true
    element: document.getElementById('fine-uploader')
    request: endpoint: '/uploads')
    template: 'test-template'

And this creates a “upload file” button (which, of course, does not work, because there is no configuration for processing this on the server site), but I would like to have this button in the input field of a simple form.

In addition, the templates do not work, I really do not understand why.

Unfortunately, the documentation does not have help for Rails.

- , :

  • ( )
  • ( )
+4
1

, , , . , , , . , , - , .

, npm. , . , , . Github:

github.com/mezis/fineuploader-rails
github.com/zakgrant/fine-uploader-rails

, .

javascript. "fine-uploader.coffee" - :

$ ->
  uploader = new (qq.FineUploader)(
    element: document.getElementById('fine-uploader')
    request:
      endpoint: '/upload'
      params:
        authenticity_token: $('#fine-uploader').data('authenticity-token')
    template: 'template-name'
    chunking:
      enabled: true
      mandatory: true
      success:
        endpoint: "/upload/finish"
)

, , , , . "" , , .

post 'upload', to: 'uploads#create'

. , , .

uploads :

def create
    file = params[:qqfile]

    #code that does whatever you need

    respond_to do |format|
       format.json {
          render json: { success: true }
       }
    end
end

( ), - qqfile. , . , . , , , ( dosc, - , refile).

, 7- javascript. CSRF.

, chunking ( ), , . , , - qquuid, params. , , , , . , , qquuid, , . :

Attachment.new(params[:qqfile], params[:qquuid])

, , ( , , ).

Attachment.where(qquuid: params[:qquuid]).combine_them_all

create , , ( , ) "", ,

chunking:
    success:
        endpoint: "/upload/finish"

( , ) . . , , , "true".

, json. , , ( json), , . , , - ( json ). , ( autoRetry true).

(haml):

#fine-uploader{"data- authenticity-token" => form_authenticity_token}
%script#template-name
    Here goes the template

, , ( ). , , , , , qquuid . params , CSRF "create" uploads.

. , -.

EDIT: , Panczo

+9

All Articles