Skip to content

Instantly share code, notes, and snippets.

@ch1ago
Created April 8, 2013 01:10
Show Gist options
  • Save ch1ago/5333453 to your computer and use it in GitHub Desktop.
Save ch1ago/5333453 to your computer and use it in GitHub Desktop.
# t.string "key"
# t.string "val"
class MyConfig < ActiveRecord::Base
class << self
def all_as_hash
begin
Rails.cache.fetch(:my_config_hash) do
h = {}
all.each { |m| h[m.key] = m.val }
h
end
rescue
{}
end
end
end
after_save do
Rails.cache.delete(:my_config_hash)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment