Ich habe ein seltsames Problem. Wenn ich eine AJAX-Anfrage mache, erhalte ich einen Fehler, wenn die Instanzvariablen "null" sind. Es scheint, dass die Anfrage nichts vom Controller erhält.Schienen 3.2.1 fehlende sofortige Variablen auf AJAX Antwort; Ruby 1.9.3
Das hat auf anderen PCs funktioniert, ich bin jetzt auf einer neuen Ubuntu-Installation. Einige Einstellungen sind möglicherweise falsch.
Ich gehe durch diese js Funktion.
jQuery.fn.mark_todo_done = function(){
this.live('click', function() {
$('.spinning').show();
var todo_id = $(this).attr("id");
$.getScript("/mark_todo_done/" + todo_id)
})
};
geht es auf dieser Strecke routes.rb
match "/mark_todo_done/:id" => "private#mark_todo_done", :as => :mark_todo_done
und diese Methode in der
privatecontroller
def mark_todo_done
@firm = current_user.firm
@todo = Todo.find(params[:id])
@project = @todo.project
if @todo.completed == true
@todo.completed = false
else
@todo.completed = true
end
@todo.update_attributes(params[:todo])
@done_todos = @project.todos.where(["completed = ?", true]).includes(:user)
@not_done_todos = @project.todos.where(["completed = ?", false]).includes(:user)
respond_to do |format|
format.js
end
end
Ich erhalte diese Fehlermeldung
ActionView::Template::Error (Called id for nil, which would mistakenly be 4 -- if you really wanted the id of nil, use object_id):
1:
2: $("#todo_<%= escape_javascript(@todo.id.to_s) %>").remove();
3: <% if @todo.completed == true %>
4: $("#done_tasks").append("<%= escape_javascript(render(:partial => @todo)) %>");
5:
app/views/private/mark_todo_done.js.erb:2:in `_app_views_private_mark_todo_done_js_erb___267824823023937232_51228900'
Ich bekomme ähnliche Fehler bei allen AJAX-Anfragen. Irgendwelche Ideen?
Ich habe dies auch in meinem application.js
jQuery.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})