Hours icon indicating copy to clipboard operation
Hours copied to clipboard

Symbol with underscores causes error in cache_helper.rb

Open secondstreetmedia opened this issue 10 years ago • 1 comments

When passing a symbol with underscores (e.g. :my_things) to the _cache_keys_for_all_ method in app/helpers/cache_helper.rb, such as in the following line:

localized_cache cache_keys_for_all(:my_things) do

it throws the following error:

LoadError - Unable to autoload constant My_thing

due to the code in line 9 of the file, which appears in the _cache_key_for_all_ method, called by the _cache_keys_for_all_ method:

9: klass = klass_name.to_s.singularize.capitalize.constantize

Using the example of :my_things, this line will try to set klass to "My_thing", triggering the error when it attempts to constantize.

I believe it should be:

9: klass = klass_name.to_s.singularize.camelize.constantize

which would set klass to "MyThing", which seems to be the correct form.

secondstreetmedia avatar Aug 20 '15 23:08 secondstreetmedia

Nice catch, your proposed change makes sense, I'd love to see a PR with it!

jurre avatar Aug 21 '15 07:08 jurre