Note that there are some explanatory texts on larger screens.

plurals
  1. PORails UJS rendering js.erb template in IE
    text
    copied!<p>I have a RoR app running rails 2.3.8 which makes use of the Rails 3 style UJS to bind data-remote forms instead of using form_for_remote, the controller responds with a js.erb file from the server.</p> <p>Works beautifully in FF, Chrome, and Safari, but when run in IE it prompts you to save a file and does not execute the JS. My research so far has turned up no possible reasons for this, so any help would be greatly appreciated!</p> <p>Here's my controller action: </p> <pre><code> def create @note = Note.create(params[:note].merge(:author_id =&gt; current_user.id)) respond_to do |format| format.js {} end end </code></pre> <p>I've also tried this instead of the respond_to block which has the same result:</p> <pre><code>render :template =&gt; "notes/create.js.erb", :content_type =&gt; 'text/javascript' </code></pre> <p>And my create.js.erb:</p> <pre><code>$('#notes').append('&lt;%= escape_javascript(render(:partial =&gt; "notes/note", :locals =&gt; {:note =&gt; @note}))%&gt;'); $('.new_note textarea').val(''); </code></pre> <p>It's all pretty straight forward, I really don't get what's going wrong with IE.</p> <p>Thanks for any help!</p> <p>Edit:</p> <p>Form that posts the note:</p> <pre><code>&lt;% form_for @note, :url =&gt; notes_path, :html =&gt; { 'data-remote' =&gt; true, :class =&gt; 'new_note'} do |f|%&gt; &lt;%= f.hidden_field :parent_id %&gt; &lt;%= hidden_field_tag :note_type, note_type%&gt; &lt;%= f.text_area :body, :size =&gt; size%&gt; &lt;br/&gt; &lt;%= f.submit "Add Note"%&gt; &lt;% end %&gt; </code></pre> <p>And the relelvent part of rails.js:</p> <pre><code>$('form[data-remote]').live('submit', function (e) { $(this).callRemote(); e.preventDefault(); }); /** * Handles execution of remote calls firing overridable events along the way */ callRemote: function () { var el = this, method = el.attr('method') || el.attr('data-method') || 'GET', url = el.attr('action') || el.attr('href'), dataType = el.attr('data-type') || 'script'; if (url === undefined) { throw "No URL specified for remote call (action or href must be present)."; } else { if (el.triggerAndReturn('ajax:before')) { var data = el.is('form') ? el.serializeArray() : []; $.ajax({ url: url, data: data, dataType: dataType, type: method.toUpperCase(), beforeSend: function (xhr) { el.trigger('ajax:loading', xhr); }, success: function (data, status, xhr) { el.trigger('ajax:success', [data, status, xhr]); }, complete: function (xhr) { el.trigger('ajax:complete', xhr); }, error: function (xhr, status, error) { el.trigger('ajax:failure', [xhr, status, error]); } }); } el.trigger('ajax:after'); } } </code></pre> <p>The server responds with: Content-Type:text/javascript; charset=utf-8</p> <p>I've tried explicitly setting data-type for the rails.js helper, but that did not change anything.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload