Hi Guys ,
I am a newbie to rails so forgive me if this has been
answered before. I am currently doing an inventory management project
on RoR and got 3 tables , goods , customers and staff. I used scaffold
to generate all of them.
I just generated a new scaffold called search and I
need to search values from all 3 tables. i am using the steps from
this site ,
http://wiki.rubyonrails.org/rails/pages/HowToImplementSearch
The only change is from Person/people to Book/books .But I keep
getting this error
You have a nil object when you didn''t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
Can someone help? The places where I put the codes are below ,
def search
query = params[:q]
@people = Person.find(:all, :conditions => ["name = ?", query])
end
is in search_controller.rb
the codes for view are in view/search/index.rhtml and search.rhtml.
Thank you so much!!
regards
billy
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
billy am wrote:> I just generated a new scaffold called search and I > need to search values from all 3 tables. i am using the steps from > this site , > > http://wiki.rubyonrails.org/rails/pages/HowToImplementSearch > > The only change is from Person/people to Book/books .But I keep > getting this error > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occurred while evaluating nil.each > > Can someone help? The places where I put the codes are below , > > def search > query = params[:q] > @people = Person.find(:all, :conditions => ["name = ?", query]) > end > > is in search_controller.rb > > the codes for view are in view/search/index.rhtml and search.rhtml. > Thank you so much!! > > regards > billy >Hi Billy, Can you check for typos? As the message suggests, it seems that one of the arrays you are evaluating in the view does not actually have any data in it. Perhaps, you have a typo like @book instead of @books or something in your view.. would be worth checking, in my opinion. Does Rails show you the code where the error occurs? Could you post that? Cheers Mohit. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
The case is closed :P Thanks to Mohit for the help! regards billy On 3/22/07, Mohit Sindhwani <mo_mail-RxrYI66vbj0AvxtiuMwx3w@public.gmane.org> wrote:> > billy am wrote: > > I just generated a new scaffold called search and I > > need to search values from all 3 tables. i am using the steps from > > this site , > > > > http://wiki.rubyonrails.org/rails/pages/HowToImplementSearch > > > > The only change is from Person/people to Book/books .But I keep > > getting this error > > > > You have a nil object when you didn''t expect it! > > You might have expected an instance of Array. > > The error occurred while evaluating nil.each > > > > Can someone help? The places where I put the codes are below , > > > > def search > > query = params[:q] > > @people = Person.find(:all, :conditions => ["name = ?", query]) > > end > > > > is in search_controller.rb > > > > the codes for view are in view/search/index.rhtml and search.rhtml. > > Thank you so much!! > > > > regards > > billy > > > > Hi Billy, > > Can you check for typos? As the message suggests, it seems that one of > the arrays you are evaluating in the view does not actually have any > data in it. Perhaps, you have a typo like @book instead of @books or > something in your view.. would be worth checking, in my opinion. > > Does Rails show you the code where the error occurs? Could you post that? > > Cheers > Mohit. > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---