Q:

Rails 3, Haml, Javascript - how to put javascript's variable into a partial

I have image upload, where I check, how big part of image is already uploaded - I do it this way:
jQuery - displaying progress bar
---
   uploader.bind('FilesAdded', function(up, files) {    
      $.each(files, function(i, file) {
        $('#filelist').append('#{escape_javascript(render(:partial => "form", :locals => {:file_id => file.id}))}');
      });

      up.refresh();
      uploader.start();
    });

    uploader.bind('UploadProgress', function(up, file) {  
      $('#'+file.id).find('strong').html('<span>' + file.percent + "%</span>");
      $('#'+file.id).find('.bar').css('width',file.percent+"%");
    });

form.html.haml
---
#form_data
  %div{:id => file_id, :style => "width:330px;"}
  ...

And I am getting the error 
undefined local variable or method `file' for #<#<Class:0x0000010161c0b8>:0x0000012a3b1f20>

Originally, I had the project in the ERB and on the place, where is now rendering of the partial  file was the content of this file - but now I converted the project to HAML and the code for displaying "progress bar" moved the code to the partial file, but now I am getting this error...
Could anyone help me, please, how to fix this problem? Thank you

A:

It looks like you're trying to include javascript in your HAML file. If so, you should use the :javascript HAML filter http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#javascript-filter in your partial.
:javascript
  uploader.bind('FilesAdded', function(up, files) {    
  $.each(files, function(i, file) {
    $('#filelist').append('#{escape_javascript(render(:partial => "form", :locals => {:file_id => file.id}))}');
  });
  ...

