You have a nil object when you didn't expect it ?

Hello,

I'm trying a simple AJAX test link with the following code inside my view :

<%= link_to_remote( "[Total]", { :action => "total", :update => "letotal" } ) %>

<div id="letotal"> </div>

In my controller I put :

def total         @res = Person.find(:all)         render_text "Il y a #{@res.size} personnes dans le carnet" end

When I test it, I get the following error message :

You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.

Thank you for your help

Hello,

I'm trying a simple AJAX test link with the following code inside my view :

<%= link_to_remote( "[Total]", { :action => "total", :update => "letotal" } ) %>

<div id="letotal"> </div>

In my controller I put :

def total        @res = Person.find(:all)        render_text "Il y a #{@res.size} personnes dans le carnet" end

Unrelated to this but it's way way more efficient to say
@number_of_people = Person.count rather that use Person.find(:all).size

When I test it, I get the following error message :

You have a nil object when you didn't expect it! You might have expected an instance of ActiveRecord::Base. The error occurred while evaluating nil.

What's the line throwing that exception ?

Fred

**on <%= link_to_remote( “[Total]”, { :action => “total”, :update =>

“letotal” } ) %>**

If I put it in comment there’s no error.

on <%= link_to_remote( "[Total]", { :action => "total", :update => > "letotal" } ) %>

If I put it in comment there's no error.

D'oh. That should be link_to_remote "[Total"], :url => {:action =>
'total'}, :update => 'letotal'

Fred

c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/url_rewriter.rb:102:in `rewrite_url'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/url_rewriter.rb:88:in `rewrite'

c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_controller/base.rb:621:in `url_for'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/helpers/url_helper.rb:76:in `send'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/helpers/url_helper.rb:76:in `url_for'

c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/helpers/prototype_helper.rb:461:in `remote_function'
c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.1.0/lib/action_view/helpers/prototype_helper.rb:255:in `link_to_remote'

app/views/carnet/voir.html.erb:15:in `_run_erb_47app47views47carnet47voir46html46erb'

Thank you Fred