4

I've a problem with my Rails 3 app: I've a script in my view to display a progress bar for an upload (the upload process works):

<h1>Ajouter des images:</h1>

<%= form_for [:admin, :gallery,  @painting], html: { multipart: true} do |f| %>

  <%= f.hidden_field :gallery_id %>

  <%= f.label :image, "Upload paintings:" %>

  <%= f.file_field :image, multiple: true, name: "painting[image]" %>

<% end %>

<script id="template-upload" type="text/x-tmpl">
  <div class="upload">
    {%=o.name%}
    <div class="progress"><div class="bar" style="width: 0%"></div></div>
  </div>
</script>

But when i try to upload a file, i got this error:

Uncaught Error: Syntax error, unrecognized expression: <div class="upload">
  Argentina.gif
  <div class="progress"><div class="bar" style="width: 0%"></div></div>
</div> 

Coming form the jquery.js file:

Sizzle.error = function( msg ) {
    throw new Error( "Syntax error, unrecognized expression: " + msg );

I really don't know how to fix it, i've already sought a lot ! Thanks for your help !

khcr
  • 103
  • 1
  • 8

4 Answers4

14

This is happening because of the identation inside your template tag. Check it out: jquery-htmlstring-versus-jquery-selectorstring

You can avoid it by using $.parseHTML():

data.context = $($.parseHTML(tmpl("template-upload", file))[1])
aelesbao
  • 503
  • 4
  • 14
0

jquery-file-upload has a compatibility problem in ruby 1.9.x. There was a recent fix https://github.com/blueimp/jQuery-File-Upload/pull/2031

Others were having the same problem (myself included) https://github.com/waynehoover/s3_direct_upload/issues/47.

Try updating your gem with bundle update jquery-fileupload-rails. (I assume you're using that gem.)

IAmNaN
  • 10,305
  • 3
  • 53
  • 51
0

Remove Jquery function $( ) when you use template. This is compatible with Jquery 1.9.1. You should process template like bellow

tmpl("template-upload", {file: file, icon: icon_name[type]})

instead of

$(tmpl("template-upload", {file: file, icon: icon_name[type]}))
vladimeeer
  • 43
  • 3
0

Using the latest version of jquery, add tril to it should do the trick

$(tmpl("template-upload", {file: file, icon: icon_name[type]}).trim())
Uchenna
  • 4,059
  • 6
  • 40
  • 73