1

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

1
  • This is a Ruby error, it has nothing to do with javascript. Commented Mar 1, 2012 at 21:00

1 Answer 1

3

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}))}');
  });
  ...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.