Loading jQuery file Cannot call method '_adjustMaxNumberOfFiles' from undefined

I am implementing the jQuery File Upload plugin in a Rails 3.2 application and I get this error message:

Uncaught TypeError: Cannot call method '_adjustMaxNumberOfFiles' of undefined

Here is the code that calls _adjustMaxNumberOfFiles:

$(function () {
    // Initialize the jQuery File Upload widget:
    $('#fileupload').fileupload(
      {
        url: '/photos', // post to and retrieve from
        dataType: 'json'
      }
    );

    // Load existing files:
    $.getJSON($('#fileupload').prop('action'), function (files) {
      var fu = $('#fileupload').data('fileupload'), 
          files = jQuery.grep(files, function (a) { return a.gallery_id == <%= params[:id] %>; }), //filter the photos down to this gallery
          template;


      fu._adjustMaxNumberOfFiles(-files.length);
      template = fu._renderDownload(files).appendTo($('#fileupload .files'));

      // Force reflow:
      fu._reflow = fu._transition && template.length && template[0].offsetWidth;
      template.addClass('in');
      $('#loading').remove();
    });

  });

It worked. I moved on to working on the rest of the application, and when I deployed to the staging environment, I noticed that I got the error above. I went back to the developer to make sure this was happening there, and it really is. I use jquery-fileupload-rails gem to load the necessary files into the asset pipeline. I tried not to use the gem and load all the assets manually, and that doesn't help.

, fu fu._adjustMaxNumberOfFiles, Cannot call method '_adjustMaxNumberOfFiles' of undefined. _adjustMaxNumberOfFiles, , _renderDownload undefined. - , jquery-file-upload, , . . js, .

<script src="/assets/jquery.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery_ujs.js?body=1" type="text/javascript"></script>
<script src="/assets/bootstrap.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-fileupload/vendor/jquery.ui.widget.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-fileupload/vendor/load-image.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-fileupload/vendor/canvas-to-blob.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-fileupload/vendor/tmpl.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-fileupload/jquery.iframe-transport.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-fileupload/jquery.fileupload.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-fileupload/jquery.fileupload-fp.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-fileupload/jquery.fileupload-ui.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-fileupload/locale.js?body=1" type="text/javascript"></script>
<script src="/assets/jquery-fileupload/index.js?body=1" type="text/javascript"></script>

. . , , , , JavaScript, jQuery.

+5
2

uploads_controller :

format.json { render json: {files: [@upload.to_jq_upload]}, status: :created, location: @upload }

js:

var fu = $('#fileupload').data('blueimpFileupload');
+5

All Articles