I am having a strange problem. Whenever I do a AJAX request I get an error about the instance variables being “nil”. It seems that the request does not get anything from the controller.
This has worked on other PC’s, I am now on a new ubuntu install. Some settings might be wrong.
I go trough this js function.
jQuery.fn.mark_todo_done = function (){
this.live('click', function() {
$('.spinning').show();
var todo_id = $(this).attr("id");
$.getScript("/mark_todo_done/" + todo_id)
})
};
it goes to this route
routes.rb
match "/mark_todo_done/:id" => "private#mark_todo_done", :as => :mark_todo_done
And this method in the
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
I get this error message
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'
I get similar errors on all AJAX requests. Any ideas?
I also have this in my application.js
jQuery.ajaxSetup({
'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}
})
The solution
Get rid of a call to private in the privatecontroller
Hope it helps somone…