# NoMethodError: You have a nil object when you didn't expect

**URL:** <https://www.ruby-forum.com/t/nomethoderror-you-have-a-nil-object-when-you-didnt-expect/189250>\
**Category:** Rails\
**Created:** [May 27, 2010, 1:43pm UTC](https://www.ruby-forum.com/t/nomethoderror-you-have-a-nil-object-when-you-didnt-expect/189250 "2010-05-27T13:43:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmanivannancse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@jmanivannancse](https://www.ruby-forum.com/u/jmanivannancse)\
**Post date:** [May 27, 2010, 1:43pm UTC](https://www.ruby-forum.com/t/nomethoderror-you-have-a-nil-object-when-you-didnt-expect/189250/1 "2010-05-27T13:43:43Z")

</div>

Hi,

I have tried to use searchlogic in my application…  
in def index,  
@search = AccounDetail.search(params[:search])  
@account\_details = @search.all

In index.rhtml  
\<%form\_for @search do |f|%\>

\<%=f.label :name\_like,"Name"%\> \<%=f.text\_field :name\_like%\> \<%=submit\_tag :Search,:name=\>nil%\>

\<%end%\>

I didn’t get any search result…  
i tried it with ruby script/console.  
when i call @search.all, i got “NoMethodError: You have a nil object  
when you didn’t expect”

example

> > search=AccountDetail.search(:name\_like\_any=\>“xx”)  
> > search.all

give me a suggestion to solve this problem

---

<div class="post-metadata">

**Author:** ![jmanivannancse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@jmanivannancse](https://www.ruby-forum.com/u/jmanivannancse)\
**Post date:** [May 29, 2010, 8:26am UTC](https://www.ruby-forum.com/t/nomethoderror-you-have-a-nil-object-when-you-didnt-expect/189250/2 "2010-05-29T08:26:33Z")

</div>

On May 28, 9:39 am, Mathew A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > I have tried to use searchlogic in my application…
> > 
> > \>\>search.all removed\_email\_address@domain.invalid

I left the rails application then I tried in ruby script/console

search=BankingDetail.search(:name\_like\_all=\>“man”)  
search.all

i got error when i call ‘all’ method

NoMethodError: 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.[]

---

<div class="post-metadata">

**Author:** ![jmanivannancse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@jmanivannancse](https://www.ruby-forum.com/u/jmanivannancse)\
**Post date:** [May 29, 2010, 8:34am UTC](https://www.ruby-forum.com/t/nomethoderror-you-have-a-nil-object-when-you-didnt-expect/189250/3 "2010-05-29T08:34:10Z")

</div>

On May 28, 9:39 am, Mathew A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > I have tried to use searchlogic in my application…
> > 
> > \>\>search.all removed\_email\_address@domain.invalid

I left the rails application then I tried in ruby script/console

search=BankingDetail.search(:name\_like\_all=\>“man”)  
search.all

i got error when i call ‘all’ method

NoMethodError: 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.[]

---

<div class="post-metadata">

**Author:** ![jmanivannancse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@jmanivannancse](https://www.ruby-forum.com/u/jmanivannancse)\
**Post date:** [May 28, 2010, 8:52am UTC](https://www.ruby-forum.com/t/nomethoderror-you-have-a-nil-object-when-you-didnt-expect/189250/4 "2010-05-28T08:52:25Z")

</div>

da manu.this prob is related with routes.yor are suppose to put  
that  
method in routes.rb

On Thu, May 27, 2010 at 5:13 PM, Manivannanj J. \<  
removed\_email\_address@domain.invalid\> wrote:

> \<%=f.label :name\_like,“Name”%\>
> 
> You received this message because you are subscribed to the Google G.  
> “Ruby on Rails: Talk” group.  
> To post to this group, send email to removed\_email\_address@domain.invalid.  
> To unsubscribe from this group, send email to  
> removed\_email\_address@domain.invalid[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> .  
> 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).

## –

Thanks & Regards,

Mathew A.  
Software Programmer(ROR)  
Maxxion Technologies Inc  
Kakkanad - Cochin  
Mob:+91 -9846476386  
Email(y) :removed\_email\_address@domain.invalid  
Email(G):removed\_email\_address@domain.invalid  
Blog:[http://electronicstrainer.blogspot.com](http://electronicstrainer.blogspot.com)
