#94 ✓resolved
Josh

nil object error

Reported by Josh | June 22nd, 2009 @ 02:31 AM

Hi, I used version 1 of SL and it worked great. Tried to follow directions for installing v2, and getting the following errors. Your help is greatly apreciated.

Rails v2.2.2

Only 1 model, no associations!

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

RAILS_ROOT: /home/josh/sites/jVilleCem
Application Trace | Framework Trace | Full Trace

vendor/rails/activerecord/lib/active_record/named_scope.rb:114:in initialize'<br/> vendor/rails/activerecord/lib/active_record/named_scope.rb:92:innew'
vendor/rails/activerecord/lib/active_record/named_scope.rb:92:in named_scope'<br/> vendor/rails/activerecord/lib/active_record/named_scope.rb:96:incall'
vendor/rails/activerecord/lib/active_record/named_scope.rb:96:in scoped'<br/> vendor/gems/binarylogic-searchlogic-2.0.1/lib/searchlogic/search.rb:85:inmethod_missing'
app/controllers/records_controller.rb:6:in index'

Controller code:

  @search = Record.search(params[:search])
  @records = @search.all

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson June 24th, 2009 @ 02:08 AM

    • State changed from “new” to “open”

    What does your params[:search] hash look like?

  • Josh

    Josh June 24th, 2009 @ 02:24 AM

    Good evening Ben.

    params[:search] should be nil, this is on the first load of the page before any search has been submitted.

    Thanks for your help.

    .....Josh.....

  • Josh

    Josh June 24th, 2009 @ 02:41 AM

    Oh and when I try from the console, I can create the search object without a problem. When I call s.all I get the same error as above.

    Thanks,

    .....Josh.....

  • Kevin W

    Kevin W July 5th, 2009 @ 09:45 PM

    I have this same issue as well. I receive this error upon submitting a search.

  • Ben Johnson

    Ben Johnson July 6th, 2009 @ 12:29 AM

    Is there any way you can tell me how to recreate the problem. I can't do it for the life of me. I am using it just fine in a few apps of mine and everything I tried in the console worked fine.

  • Kevin W

    Kevin W July 6th, 2009 @ 11:20 AM

    Hi Ben,

    I initially started working with v1.6.6 via a gem install and was using the .new_search method just dandy like so:

    @search = Product.new_search
    

    My search form operates as a partial (_search.html.erb) within the 'index.html.erb' view for my Product class. The form submits my :search hash to my 'search' action like so:

    <% form_tag :controller => "products", :action => "search" do -%>
      <h2>Search</h2>
        <%= label_tag 'search[collection_id]', "COLLECTION" %>
        <%= select_tag 'search[collection_id]', '<option value="">Any collection</option>'+options_for_select(@collections.collect {|p| [p.name, p.id] }) %> &nbsp;&nbsp;&nbsp;
        <%= label_tag 'search[style_id]', "STYLE" %>
        <%= select_tag 'search[style_id]', '<option value="">Any style</option>'+options_for_select(@styles.collect {|p| [p.name, p.id] }) %> &nbsp;&nbsp;&nbsp;
        <%= label_tag 'search[name]', "KEYWORD" %>
        <%= text_field_tag 'search[name]' %><br />
        <%= submit_tag 'Search' %>
    <% end -%>
    

    I then conditionally process each search parameter:

    unless params[:search][:collection_id].nil? || params[:search][:collection_id] == ''
      @search.collection_id_equals = params[:search][:collection_id]
    end
    unless params[:search][:style_id].nil? || params[:search][:style_id] == ''
      @search.style_id_equals = params[:search][:style_id]
    end
    unless params[:search][:name].nil? || params[:search][:name] == ''
      @search.name_contains = params[:search][:name]
    end
    

    Later, I updated to v2.1.1 and switched to using .search instead. I now receive the following:

    * NoMethodError in ProductsController#search

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

    /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/named_scope.rb:114:in initialize' /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/named_scope.rb:92:innew' /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/named_scope.rb:92:in named_scope' /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/named_scope.rb:96:incall' /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/named_scope.rb:96:in scoped' /Library/Ruby/Gems/1.8/gems/searchlogic-2.1.2/lib/searchlogic/search.rb:95:inmethod_missing' app/controllers/products_controller.rb:48:in search'<br/> /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:insend' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:1253:in perform_action_without_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:617:incall_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:610:in perform_action_without_benchmark' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:inperform_action_without_rescue' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/benchmarking.rb:68:in perform_action_without_rescue' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/rescue.rb:136:inperform_action_without_caching' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:13:in perform_action' /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/connection_adapters/abstract/query_cache.rb:34:incache' /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/query_cache.rb:8:in cache' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/caching/sql_cache.rb:12:inperform_action' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:in send' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:524:inprocess_without_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/filters.rb:606:in process_without_session_management_support' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/session_management.rb:134:inprocess' /Library/Ruby/Gems/1.8/gems/actionpack-2.2.2/lib/action_controller/base.rb:392:in process' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:inload_without_new_constant_marking' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in load' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:innew_constants_in' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:142:in load' /Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/commands/servers/mongrel.rb:64 /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:inrequire' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:521:in new_constants_in' /Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:153:inrequire' /Library/Ruby/Gems/1.8/gems/rails-2.2.2/lib/commands/server.rb:49 *

    Thoughts?

  • dwatts

    dwatts July 6th, 2009 @ 01:43 PM

    Hi Ben,

    Had similar problems. I found two problems on my project.

    1 - I was using Rails 2.2.2. I upgraded to 2.3.2 and set this in my environment.
    Don't know why but after this the "The error occurred while evaluating nil.[]" error went away. Why?

    After this... dooh
    2 - I started getting an "Uninitialized constant ApplicationController" error.
    Did I mention this was an old project :-) Googled and found that the old application controller needed to be renamed from application.rb to application_controller.rb.

    As of now all of the new searchlogic features are now working for me

    My two cents... please code responsibly, safe and insane

  • Kevin W

    Kevin W July 6th, 2009 @ 03:02 PM

    dwatts,

    I did just as you said. Upgraded to 2.3.2, set the version in my environment.rb, and renamed application.rb to application_controller.rb. All's well! Thanks so much for posting this!

  • Josh

    Josh July 7th, 2009 @ 02:08 AM

    Yeah, thanks dwatts. Upgraded Rails to 2.3.2 and working like a charm.

    .....Josh.....

  • Ben Johnson

    Ben Johnson July 19th, 2009 @ 01:27 PM

    • State changed from “open” to “resolved”

    Thanks for the updates, I'll consider this resolved. Let me know if you have any more issues.

  • seomaster

    seomaster April 11th, 2021 @ 04:26 AM

    I exploit solely premium quality products -- you will observe these individuals on: check this site

  • seomaster

    seomaster April 11th, 2021 @ 04:29 AM

    I should assert barely that its astounding! The blog is informational also always fabricate amazing entitys. check this site

  • seomaster

    seomaster April 11th, 2021 @ 04:30 AM

    It is fine, nonetheless evaluate the information and facts around this correct. check this site

  • seomaster

    seomaster April 14th, 2021 @ 06:43 AM

    I am always searching online for storys that can accommodate me. There is obviously a multiple to understand about this. I feel you made few salubrious points in Attributes moreover. Detain busy, awesome career! online casino

  • seomaster

    seomaster April 14th, 2021 @ 08:10 AM

    Cool you write, the information is very good and interesting, I'll give you a link to my site. online casino

  • seomaster

    seomaster April 15th, 2021 @ 12:10 AM

    This is very useful, although it will be important to help simply click that web page link: casino online canada

  • seomaster

    seomaster April 15th, 2021 @ 12:24 AM

    It's superior, however , check out material at the street address. casino online canada

  • seomaster

    seomaster April 15th, 2021 @ 12:38 AM

    Cool you write, the information is very good and interesting, I'll give you a link to my site. casino online canada

  • seomaster

    seomaster April 16th, 2021 @ 12:07 AM

    This is very useful, although it will be important to help simply click that web page link: check here,

  • seomaster

    seomaster April 16th, 2021 @ 12:23 AM

    It's superior, however , check out material at the street address. check here,

  • seomaster

    seomaster April 16th, 2021 @ 12:38 AM

    Cool you write, the information is very good and interesting, I'll give you a link to my site. check here,

  • seomaster

    seomaster April 16th, 2021 @ 11:13 PM

    It's superior, however , check out material at the street address. online casino canada real money

  • seomaster

    seomaster April 16th, 2021 @ 11:26 PM

    Cool you write, the information is very good and interesting, I'll give you a link to my site. online casino canada real money

  • seomaster

    seomaster April 17th, 2021 @ 12:45 AM

    This is very useful, although it will be important to help simply click that web page link: online casino canada real money

  • seomaster

    seomaster April 17th, 2021 @ 07:22 PM

    It is quite beneficial, although think about the facts when it reaches this target. Lambingan

  • seomaster

    seomaster April 17th, 2021 @ 07:33 PM

    I personally use them exclusively high-quality elements : you will notice these folks during: Lambingan

  • seomaster

    seomaster April 17th, 2021 @ 07:48 PM

    These websites are really needed, you can learn a lot. Lambingan

  • seomaster

    seomaster April 18th, 2021 @ 11:11 PM

    I can give you the address Here you will learn how to do it correctly. Read and write something good. kasyno online

  • seomaster

    seomaster April 18th, 2021 @ 11:21 PM

    It is especially decent, though look into the tips during this home address. kasyno online

  • seomaster

    seomaster April 18th, 2021 @ 11:40 PM

    Such sites are important because they provide a large dose of useful information ... kasyno online

  • seomaster

    seomaster April 19th, 2021 @ 07:38 PM

    This is very useful, although it will be important to help simply click that web page link: visit this page,

  • seomaster

    seomaster April 19th, 2021 @ 07:46 PM

    It's superior, however , check out material at the street address. visit this page,

  • seomaster

    seomaster April 19th, 2021 @ 08:23 PM

    Cool you write, the information is very good and interesting, I'll give you a link to my site. visit this page,

  • seomaster

    seomaster April 20th, 2021 @ 07:35 PM

    I can give you the address Here you will learn how to do it correctly. Read and write something good. kasyna online

  • seomaster

    seomaster April 20th, 2021 @ 07:41 PM

    It is especially decent, though look into the tips during this home address. kasyna online

  • seomaster

    seomaster April 20th, 2021 @ 08:24 PM

    Such sites are important because they provide a large dose of useful information ... kasyna online

  • seomaster

    seomaster April 21st, 2021 @ 05:46 AM

    This is very useful, although it will be important to help simply click that web page link: keno online

  • seomaster

    seomaster April 21st, 2021 @ 05:55 AM

    It's superior, however , check out material at the street address. keno online

  • seomaster

    seomaster April 21st, 2021 @ 07:08 PM

    Cool you write, the information is very good and interesting, I'll give you a link to my site. keno online

  • seomaster

    seomaster April 22nd, 2021 @ 11:28 PM

    Your blogs further more each else volume is so entertaining further serviceable It appoints me befall retreat encore. I will instantly grab your rss feed to stay informed of any updates. ranking kasyn

  • seomaster

    seomaster April 22nd, 2021 @ 11:59 PM

    Actually I read it yesterday but I had some thoughts about it and today I wanted to read it again because it is very well written. ranking kasyn

  • seomaster

    seomaster April 24th, 2021 @ 08:13 PM

    This is very appealing, however , it is very important that will mouse click on the connection: site,

  • seomaster

    seomaster April 24th, 2021 @ 08:24 PM

    I came onto your blog while focusing just slightly submits. Nice strategy for next, I will be bookmarking at once seize your complete rises... learn more,

  • seomaster

    seomaster April 24th, 2021 @ 08:39 PM

    I really appreciate this wonderful post that you have provided for us. I assure this would be beneficial for most of the people. learn more,

  • seomaster

    seomaster April 26th, 2021 @ 12:10 AM

    I can give you the address Here you will learn how to do it correctly. Read and write something good. casino online

  • seomaster

    seomaster April 26th, 2021 @ 12:22 AM

    It is especially decent, though look into the tips during this home address. casino online

  • seomaster

    seomaster April 26th, 2021 @ 12:36 AM

    Such sites are important because they provide a large dose of useful information ... casino online

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Provides common named scopes and object based searching.

People watching this ticket

Tags

Pages