简体   繁体   English

Rails 3,Haml,Javascript - 如何将javascript的变量放入局部

[英]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... 最初,我在ERB和地方有项目,现在渲染部分文件是这个文件的内容 - 但现在我将项目转换为HAML,显示“进度条”的代码将代码移动到部分文件,但现在我收到此错误...

Could anyone help me, please, how to fix this problem? 任何人都可以帮助我,如何解决这个问题? Thank you 谢谢

It looks like you're trying to include javascript in your HAML file. 看起来你正试图在你的HAML文件中包含javascript。 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 HAML过滤器http://haml-lang.com/docs/yardoc/file.HAML_REFERENCE.html#javascript-filter

:javascript
  uploader.bind('FilesAdded', function(up, files) {    
  $.each(files, function(i, file) {
    $('#filelist').append('#{escape_javascript(render(:partial => "form", :locals => {:file_id => file.id}))}');
  });
  ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM