nkallen / cache-money

A Write-Through Cacheing Library for ActiveRecord
Apache License 2.0
995 stars 107 forks source link

Locale plugin error #1

Open ashleym1972 opened 15 years ago

ashleym1972 commented 15 years ago

When I ran with the Locale plugin I got this error: NoMethodError (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.indices): (DELEGATION):2:in __send__' (__DELEGATION__):2:inindices' (DELEGATION):2:in __send__' (__DELEGATION__):2:inindices' vendor/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:114:in indexed_on?' vendor/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:56:incacheable?' vendor/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:15:in perform' vendor/gems/nkallen-cache-money-0.2.5/lib/cash/query/abstract.rb:7:inperform' vendor/gems/nkallen-cache-money-0.2.5/lib/cash/finders.rb:24:in find_every' vendor/gems/mislav-will_paginate-2.2.3/lib/will_paginate/finder.rb:164:inmethod_missing' app/controllers/application_controller.rb:69:in `set_locale_from_request'

Which was caused by the Locale ActiveRecords being located in the vendor tree and not our main tree. To solve this we added this line to abstract.rb:52

  def cacheable?(*optionss)
shanel commented 15 years ago

Has there been any other fix for this? I tried this fix out and found that it ended up meaning nothing would end up getting cached...

ashleym1972 commented 15 years ago

Sorry, I didn't update. We found the fix didn't work out. We ended up moving the Locale classes to the model. There is really no other way of fixing this.

shanel commented 14 years ago

Do you mean you moved the file that defined Locale to app/models out of vendor? Did you still have to make the change in the code?

Or do you mean you had to take the code in the Locale plugin and put it directly into any of the models that were going to use it?

shanel commented 14 years ago

Think I found the fix:

in abstract.rb:

  def indexed_on?(attributes)
    begin
      indices.detect { |index| index == attributes }
    rescue NoMethodError
      return nil 
    end 
  end
ashleym1972 commented 14 years ago

That could do it. We just moved the locale.rb file to our models directory.

xlash commented 14 years ago

That worked for me!!! for an unknown reason, this ticket's info is not easily found via a google search of the error. It would be great to integrate it into the main rep.

ngmoco commented 14 years ago

Committed it to my fork.