Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7791023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:45:42+00:00 2026-06-01T21:45:42+00:00

I am having a strange problem. Whenever I do a AJAX request I get

  • 0

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")}
})
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:45:43+00:00Added an answer on June 1, 2026 at 9:45 pm

    The solution

    Get rid of a call to private in the privatecontroller

    #private
    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
    

    Hope it helps somone…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a strange problem - I have about 14.5 million bitmap images, that
I am having a strange problem with Internet Explorer and greek encoded get variables.
I'm having a strange problem here... I have an ASP.NET 3.5 application that has
I'm having a strange problem in that I have php inserting text into a
I am having strange problem, whenever my site is loaded for the first time
I'm having a strange problem that I can't work out and wonder if anybody
I am having a strange problem. There are two ajax calls in the code.
I'm having a strange problem when trying to run a maven build that uses
I'm having a strange problem. I've got a function dbo.ufn_GetDaysInYear which seems to give
I am having a strange problem with global variables disappearing on me. Here is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.