Created
August 6, 2011 06:59
-
-
Save Nimster/1129105 to your computer and use it in GitHub Desktop.
Rails lookup v4 - Prefill the caches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def lookup(as_name) | |
#... | |
all_vals = cls.all | |
cls.class_variable_set(:@@rcaches, all_vals.inject({}) do |r, obj| | |
r[obj.name] = obj.id | |
r | |
end) | |
cls.class_variable_set(:@@caches, all_vals.inject([]) do |r, obj| | |
r[obj.id] = obj.name | |
r | |
end) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment