# Undefined method \`eq' for nil:NilClass

**URL:** <https://www.ruby-forum.com/t/undefined-method-eq-for-nil-nilclass/193479>\
**Category:** Rails\
**Created:** [August 18, 2010, 1:36pm UTC](https://www.ruby-forum.com/t/undefined-method-eq-for-nil-nilclass/193479 "2010-08-18T13:36:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [August 18, 2010, 1:36pm UTC](https://www.ruby-forum.com/t/undefined-method-eq-for-nil-nilclass/193479/1 "2010-08-18T13:36:22Z")

</div>

I’m walking through an example in the “Head First Rails” book, but,  
instead doing the examples using Rails3.0.0.rc.

But, I’m getting this error when browsing for example:

[http://localhost:3000/advs/1](http://localhost:3000/advs/1)

undefined method `eq’ for nil:NilClass

Provided that my advs\_controller.rb is as follows:

[http://pastie.org/private/cd9zntg2ite57ept288kfa](http://pastie.org/private/cd9zntg2ite57ept288kfa)

Any ideas why I’m getting that and a workaround for that?

Thanks.

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [August 18, 2010, 2:50pm UTC](https://www.ruby-forum.com/t/undefined-method-eq-for-nil-nilclass/193479/2 "2010-08-18T14:50:32Z")

</div>

What does your view look like?

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [August 18, 2010, 2:21pm UTC](https://www.ruby-forum.com/t/undefined-method-eq-for-nil-nilclass/193479/3 "2010-08-18T14:21:15Z")

</div>

On 18 August 2010 12:36, Abder-Rahman A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I’m walking through an example in the “Head First Rails” book, but,  
> instead doing the examples using Rails3.0.0.rc.
> 
> But, I’m getting this error when browsing for example:
> 
> [http://localhost:3000/advs/1](http://localhost:3000/advs/1)
> 
> undefined method `eq’ for nil:NilClass

For an error like this it is better to show the full error trace, but  
first look at it yourself. Somewhere there you will usually find a  
reference to a line of your code. Look carefully at that line and the  
error and try and work out the problem yourself. The error is saying  
that you are trying to call a method on an object that is nil. A  
common cause of this is using the result of a find operation without  
checking that it did in fact find a record.

If you still cannot see the problem then post the error trace and the  
code around the error.

> Provided that my advs\_controller.rb is as follows:
> 
> [http://pastie.org/private/cd9zntg2ite57ept288kfa](http://pastie.org/private/cd9zntg2ite57ept288kfa)

For only a few lines of code it is better in my opinion to put it  
inline rather than a pastie. Particularly consider those who may find  
the thread in months and years yet to come, hoping for enlightenment,  
only to find that the pastie has disappeared.

Colin

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [October 12, 2010, 1:40am UTC](https://www.ruby-forum.com/t/undefined-method-eq-for-nil-nilclass/193479/4 "2010-10-12T01:40:06Z")

</div>

Hi,  
This was happened when i tried to give "Model.find " option in Query  
interface.

On 6 September 2010 13:32, Kannan [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 291:in `find_one' activesupport (3.0.0) lib/active_support/dependencies.rb:591:in activesupport (3.0.0) lib/active_support/dependencies.rb:181:in `send\_action’  
> activesupport (3.0.0) lib/active\_support/callbacks.rb:93:in  
> `instrument' actionpack (3.0.0) lib/action_controller/metal.rb:173:in `block in  
> rack-mount (0.6.13) lib/rack/mount/code\_generation.rb:68:in  
> actionpack (3.0.0) lib/action\_dispatch/middleware/params\_parser.rb:  
> query\_cache.rb:28:in `cache' rack (1.2.1) lib/rack/sendfile.rb:107:in `call’  
> rack (1.2.1) lib/rack/lock.rb:11:in `call’  
> start\_thread’
> 
> > If you still cannot see the problem then post the error trace and the  
> > the thread in months and years yet to come, hoping for enlightenment,  
> > .  
> > For more options, visit this group at  
> > [http://groups.google.com/group/rubyonrails-talk?hl=en](http://groups.google.com/group/rubyonrails-talk?hl=en).

–  
With Regards  
Palani Kannan. K  
Office: +49-531-2616-226  
Mobile: +4917647098166

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [September 6, 2010, 4:39pm UTC](https://www.ruby-forum.com/t/undefined-method-eq-for-nil-nilclass/193479/5 "2010-09-06T16:39:35Z")

</div>

Hi,

Me too got same error… I attached Full trace here… Kindly suggest  
on this issue…

undefined method `eq’ for nil:NilClass

activesupport (3.0.0) lib/active\_support/whiny\_nil.rb:48:in  
`method_missing' activerecord (3.0.0) lib/active_record/relation/finder_methods.rb: 291:in`find\_one’  
activerecord (3.0.0) lib/active\_record/relation/finder\_methods.rb:  
281:in `find_with_ids' activerecord (3.0.0) lib/active_record/relation/finder_methods.rb: 107:in`find’  
activerecord (3.0.0) lib/active\_record/base.rb:439:in `find' app/models/taxa.rb:2:in`class:Taxa’  
app/models/taxa.rb:1:in `<top (required)>' activesupport (3.0.0) lib/active_support/dependencies.rb:454:in`load’  
activesupport (3.0.0) lib/active\_support/dependencies.rb:454:in `block in load_file' activesupport (3.0.0) lib/active_support/dependencies.rb:591:in`new\_constants\_in’  
activesupport (3.0.0) lib/active\_support/dependencies.rb:453:in  
`load_file' activesupport (3.0.0) lib/active_support/dependencies.rb:340:in`require\_or\_load’  
activesupport (3.0.0) lib/active\_support/dependencies.rb:491:in  
`load_missing_constant' activesupport (3.0.0) lib/active_support/dependencies.rb:183:in`block  
in const\_missing’  
activesupport (3.0.0) lib/active\_support/dependencies.rb:181:in `each' activesupport (3.0.0) lib/active_support/dependencies.rb:181:in`const\_missing’  
activesupport (3.0.0) lib/active\_support/dependencies.rb:503:in  
`load_missing_constant' activesupport (3.0.0) lib/active_support/dependencies.rb:183:in`block  
in const\_missing’  
activesupport (3.0.0) lib/active\_support/dependencies.rb:181:in `each' activesupport (3.0.0) lib/active_support/dependencies.rb:181:in`const\_missing’  
app/controllers/taxas\_controller.rb:5:in `index' actionpack (3.0.0) lib/action_controller/metal/implicit_render.rb:4:in`send\_action’  
actionpack (3.0.0) lib/abstract\_controller/base.rb:150:in  
`process_action' actionpack (3.0.0) lib/action_controller/metal/rendering.rb:11:in`process\_action’  
actionpack (3.0.0) lib/abstract\_controller/callbacks.rb:18:in `block in process_action' activesupport (3.0.0) lib/active_support/callbacks.rb:435:in`\_run\_\_402958380944449391\_\_process\_action\_\_4448255831886203218\_\_callbacks’  
activesupport (3.0.0) lib/active\_support/callbacks.rb:409:in  
`_run_process_action_callbacks' activesupport (3.0.0) lib/active_support/callbacks.rb:93:in`run\_callbacks’  
actionpack (3.0.0) lib/abstract\_controller/callbacks.rb:17:in  
`process_action' actionpack (3.0.0) lib/action_controller/metal/instrumentation.rb: 30:in`block in process\_action’  
activesupport (3.0.0) lib/active\_support/notifications.rb:52:in `block in instrument' activesupport (3.0.0) lib/active_support/notifications/instrumenter.rb: 21:in`instrument’  
activesupport (3.0.0) lib/active\_support/notifications.rb:52:in  
`instrument' actionpack (3.0.0) lib/action_controller/metal/instrumentation.rb: 29:in`process\_action’  
actionpack (3.0.0) lib/action\_controller/metal/rescue.rb:17:in  
`process_action' actionpack (3.0.0) lib/abstract_controller/base.rb:119:in`process’  
actionpack (3.0.0) lib/abstract\_controller/rendering.rb:40:in  
`process' actionpack (3.0.0) lib/action_controller/metal.rb:133:in`dispatch’  
actionpack (3.0.0) lib/action\_controller/metal/rack\_delegation.rb:  
14:in `dispatch' actionpack (3.0.0) lib/action_controller/metal.rb:173:in`block in  
action’  
actionpack (3.0.0) lib/action\_dispatch/routing/route\_set.rb:62:in  
`call' actionpack (3.0.0) lib/action_dispatch/routing/route_set.rb:62:in`dispatch’  
actionpack (3.0.0) lib/action\_dispatch/routing/route\_set.rb:27:in  
`call' rack-mount (0.6.13) lib/rack/mount/route_set.rb:148:in`block in call’  
rack-mount (0.6.13) lib/rack/mount/code\_generation.rb:93:in `block in recognize' rack-mount (0.6.13) lib/rack/mount/code_generation.rb:68:in`optimized\_each’  
rack-mount (0.6.13) lib/rack/mount/code\_generation.rb:92:in  
`recognize' rack-mount (0.6.13) lib/rack/mount/route_set.rb:139:in`call’  
actionpack (3.0.0) lib/action\_dispatch/routing/route\_set.rb:492:in  
`call' actionpack (3.0.0) lib/action_dispatch/middleware/ best_standards_support.rb:17:in`call’  
actionpack (3.0.0) lib/action\_dispatch/middleware/head.rb:14:in `call' rack (1.2.1) lib/rack/methodoverride.rb:24:in`call’  
actionpack (3.0.0) lib/action\_dispatch/middleware/params\_parser.rb:  
21:in `call' actionpack (3.0.0) lib/action_dispatch/middleware/flash.rb:182:in`call’  
actionpack (3.0.0) lib/action\_dispatch/middleware/session/  
abstract\_store.rb:149:in `call' actionpack (3.0.0) lib/action_dispatch/middleware/cookies.rb:287:in`call’  
activerecord (3.0.0) lib/active\_record/query\_cache.rb:32:in `block in call' activerecord (3.0.0) lib/active_record/connection_adapters/abstract/ query_cache.rb:28:in`cache’  
activerecord (3.0.0) lib/active\_record/query\_cache.rb:12:in `cache' activerecord (3.0.0) lib/active_record/query_cache.rb:31:in`call’  
activerecord (3.0.0) lib/active\_record/connection\_adapters/abstract/  
connection\_pool.rb:355:in `call' actionpack (3.0.0) lib/action_dispatch/middleware/callbacks.rb:46:in`block in call’  
activesupport (3.0.0) lib/active\_support/callbacks.rb:415:in  
`_run_call_callbacks' actionpack (3.0.0) lib/action_dispatch/middleware/callbacks.rb:44:in`call’  
rack (1.2.1) lib/rack/sendfile.rb:107:in `call' actionpack (3.0.0) lib/action_dispatch/middleware/remote_ip.rb:48:in`call’  
actionpack (3.0.0) lib/action\_dispatch/middleware/show\_exceptions.rb:  
46:in `call' railties (3.0.0) lib/rails/rack/logger.rb:13:in`call’  
rack (1.2.1) lib/rack/runtime.rb:17:in `call' activesupport (3.0.0) lib/active_support/cache/strategy/local_cache.rb: 72:in`call’  
rack (1.2.1) lib/rack/lock.rb:11:in `block in call' <internal:prelude>:10:in`synchronize’  
rack (1.2.1) lib/rack/lock.rb:11:in `call' actionpack (3.0.0) lib/action_dispatch/middleware/static.rb:30:in`call’  
railties (3.0.0) lib/rails/application.rb:168:in `call' railties (3.0.0) lib/rails/application.rb:77:in`method\_missing’  
railties (3.0.0) lib/rails/rack/log\_tailer.rb:14:in `call' rack (1.2.1) lib/rack/content_length.rb:13:in`call’  
rack (1.2.1) lib/rack/handler/webrick.rb:52:in `service' /usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:111:in`service’  
/usr/local/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run' /usr/local/lib/ruby/1.9.1/webrick/server.rb:183:in`block in  
start\_thread’

---

<div class="post-metadata">

**Author:** ![swengineer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/97f17d/32.png) [@swengineer](https://www.ruby-forum.com/u/swengineer)\
**Post date:** [August 18, 2010, 3:08pm UTC](https://www.ruby-forum.com/t/undefined-method-eq-for-nil-nilclass/193479/6 "2010-08-18T15:08:50Z")

</div>

Thanks for your replies.

The issue was as follows:

As I mentioned, I’m walking through an example in “Head First Rails”. I  
have used the book’s version of “development.sqlite3” that contains some  
data.

I used the name “advs” to create my application, and the table name in  
the database version I used happen to have the name “ads”.

So, I just changed the name of the table to “advs” and it worked.

Thanks.
