I have a RoR application working with rails 2.3.8 that uses Rails 3 style UJS to bind remote data forms instead of using form_for_remote, the controller responds with the js.erb file from the server.
Works great in FF, Chrome, and Safari, but when launched in IE, it offers you to save the file and not execute JS. My research has not yet led to possible reasons, so any help would be greatly appreciated!
Here is my action with the controller:
def create
@note = Note.create(params[:note].merge(:author_id => current_user.id))
respond_to do |format|
format.js {}
end
end
I also tried this instead of the response_to block, which has the same result:
render :template => "notes/create.js.erb", :content_type => 'text/javascript'
And my create.js.erb file:
$('#notes').append('<%= escape_javascript(render(:partial => "notes/note", :locals => {:note => @note}))%>');
$('.new_note textarea').val('');
Everything is pretty straight forward, I really don't understand what is happening with IE.
Thanks for any help!
Edit:
The form that sends the note:
<% form_for @note, :url => notes_path, :html => { 'data-remote' => true, :class =>
'new_note'} do |f|%>
<%= f.hidden_field :parent_id %>
<%= hidden_field_tag :note_type, note_type%>
<%= f.text_area :body, :size => size%>
<br/>
<%= f.submit "Add Note"%>
<% end %>
And the regressive part of rails.js:
$('form[data-remote]').live('submit', function (e) {
$(this).callRemote();
e.preventDefault();
});
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');
}
}
: Content-Type: text/javascript; = UTF-8
rails.js, .