Skip to content

Instantly share code, notes, and snippets.

@Nimster
Created August 6, 2011 06:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nimster/1129105 to your computer and use it in GitHub Desktop.
Save Nimster/1129105 to your computer and use it in GitHub Desktop.
Rails lookup v4 - Prefill the caches
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