cache-money icon indicating copy to clipboard operation
cache-money copied to clipboard

Locale plugin error

Open ashleym1972 opened this issue 16 years ago • 7 comments

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)
  •    return false unless @active_record.methods.include?(:indices)
    optionss.each { |options| return unless safe_options_for_cache?(options) }
    

ashleym1972 avatar Apr 28 '09 21:04 ashleym1972

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

shanel avatar Oct 07 '09 23:10 shanel

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.

ashleym1972 avatar Oct 08 '09 01:10 ashleym1972

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 avatar Oct 08 '09 20:10 shanel

Think I found the fix:

in abstract.rb:

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

shanel avatar Oct 08 '09 21:10 shanel

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

ashleym1972 avatar Oct 08 '09 21:10 ashleym1972

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.

xlash avatar Oct 09 '09 14:10 xlash

Committed it to my fork.

ngmoco avatar Oct 13 '09 17:10 ngmoco