#33 ✓resolved

nil errors after upgrading to Rails 2.2

Reported by Prometheus | November 27th, 2008 @ 01:23 PM

I recently upgraded to Rails 2.2.2. I had Searchgasm running just perfectly, and started getting this error in my controller.

I tried upgrading to the latest version of searchlogic, to no avail.

NoMethodError in MattersController#index

You have a nil object when you didn't expect it! The error occurred while evaluating nil.klass vendor/rails/activerecord/lib/active_record/reflection.rb:244:in source_reflection' vendor/rails/activerecord/lib/active_record/reflection.rb:244:incollect' vendor/rails/activerecord/lib/active_record/reflection.rb:244:in source_reflection' vendor/rails/activerecord/lib/active_record/reflection.rb:303:inderive_class_name' vendor/rails/activerecord/lib/active_record/reflection.rb:107:in class_name' vendor/plugins/searchlogic/lib/searchlogic/conditions/base.rb:269:inadd_associations!' vendor/plugins/searchlogic/lib/searchlogic/conditions/base.rb:263:in each' vendor/plugins/searchlogic/lib/searchlogic/conditions/base.rb:263:inadd_associations!' vendor/plugins/searchlogic/lib/searchlogic/conditions/base.rb:151:in initialize' vendor/plugins/searchlogic/lib/searchlogic/search/conditions.rb:17:innew' vendor/plugins/searchlogic/lib/searchlogic/search/conditions.rb:17:in initialize' vendor/plugins/searchlogic/lib/searchlogic/active_record/base.rb:140:innew' vendor/plugins/searchlogic/lib/searchlogic/active_record/base.rb:140:in searchlogic_search' vendor/plugins/searchlogic/lib/searchlogic/active_record/base.rb:65:innew_search' vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:370:in send' vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:370:inmethod_missing' vendor/rails/activerecord/lib/active_record/base.rb:2003:in with_scope_without_searchlogic' vendor/plugins/searchlogic/lib/searchlogic/active_record/base.rb:47:inwith_scope' vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:202:in send' vendor/rails/activerecord/lib/active_record/associations/association_proxy.rb:202:inwith_scope' vendor/rails/activerecord/lib/active_record/associations/association_collection.rb:366:in method_missing' app/controllers/matters_controller.rb:9:inindex' -e:2:in load' -e:2

Comments and changes to this ticket

  • Prometheus

    Prometheus November 27th, 2008 @ 01:24 PM

    Sorry, I should have mentioned when I said searchgasm was running perfectly, the same controller (no code changes) ran fine on Rails 2.1.

  • Ben Johnson

    Ben Johnson November 27th, 2008 @ 01:42 PM

    • State changed from “new” to “open”

    Its now called searchlogic, are you using the latest searchlogic gem?

  • Prometheus

    Prometheus November 27th, 2008 @ 02:33 PM

    Yes, I'm using the latest gem. Thanks - Jack.***********

  • Ben Johnson

    Ben Johnson November 30th, 2008 @ 03:25 PM

    Hi Jack,

    I updated the example to rails 2.2.2 and all seems to be working fine. Can you reproduce the problem with the example?


  • Ben Johnson

    Ben Johnson December 3rd, 2008 @ 03:14 PM

    • State changed from “open” to “resolved”
  • Prometheus

    Prometheus December 3rd, 2008 @ 03:46 PM

    Hi Ben,

    I had to roll back my app to 2.1 because of this issue, and haven't had a chance to try to reproduce it yet. I will create a branch to experiment on 2.2 with and re-open when I have a chance.

    Cheers, Jack

  • Marcel Ruegenberg

    Marcel Ruegenberg January 8th, 2009 @ 09:53 AM

    Just wanted to mention, that I also have this problem with the version from Git as of today.

    My trace:

    You have a nil object when you didn't expect it!
    The error occurred while evaluating nil.klass
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/reflection.rb:244:in `source_reflection'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/reflection.rb:244:in `collect'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/reflection.rb:244:in `source_reflection'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/reflection.rb:303:in `derive_class_name'
    /usr/lib/ruby/gems/1.8/gems/activerecord-2.2.2/lib/active_record/reflection.rb:107:in `class_name'
    vendor/plugins/searchlogic-git-20090108/lib/searchlogic/conditions/magic_methods.rb:60:in `add_associations!'
    vendor/plugins/searchlogic-git-20090108/lib/searchlogic/conditions/magic_methods.rb:56:in `each'
    vendor/plugins/searchlogic-git-20090108/lib/searchlogic/conditions/magic_methods.rb:56:in `add_associations!'
    vendor/plugins/searchlogic-git-20090108/lib/searchlogic/conditions/magic_methods.rb:46:in `initialize'
    vendor/plugins/searchlogic-git-20090108/lib/searchlogic/search/conditions.rb:17:in `new'
    vendor/plugins/searchlogic-git-20090108/lib/searchlogic/search/conditions.rb:17:in `initialize'
    vendor/plugins/searchlogic-git-20090108/lib/searchlogic/active_record/base.rb:191:in `new'
    vendor/plugins/searchlogic-git-20090108/lib/searchlogic/active_record/base.rb:191:in `searchlogic_search'
    vendor/plugins/searchlogic-git-20090108/lib/searchlogic/active_record/base.rb:65:in `new_search'
    app/controllers/users_controller.rb:9:in `init_search'
    app/controllers/users_controller.rb:27:in `index'
  • Marcel Ruegenberg

    Marcel Ruegenberg January 8th, 2009 @ 09:58 AM

    Three more things: - the failing controllers worked without problems in Rails 2.1. - I use Postgres as the database - The example site (both the adress linked to here and on searchlogic.rubyforge.org) seems to be down?

  • Ben Johnson

    Ben Johnson January 8th, 2009 @ 02:27 PM

    This is strange, I can't fix the problem if I can't reproduce it. Based on the backtrace it has something do with your associations. Go to magic_methods.rb line 60 and you will see where the problem is. I am not sure what kind of relationship is causing that.

    Lastly, my website is propagating, I had to make some DNS changes, everything should be working shortly, it is working for me.

  • Marcel Ruegenberg

    Marcel Ruegenberg January 9th, 2009 @ 03:41 AM

    I have looked into it some more and found out that the problematic association was an incorrect has_many :through in one of my models. (The association after ':through =>' didn't exist.)

    So, the problem apparently appears with faulty associations though I don't know, why this isn't a problem in Rails 2.1.0. Testing that all associations work in script/console should generally help to find the source of problems like this.

    This problem is resolved for me. Thanks.

  • Pak24tv

    Pak24tv December 9th, 2020 @ 02:03 AM

    I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post. b4u movies b4u music boogle bollywood

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.