Skip to content

Instantly share code, notes, and snippets.

@sam452
Forked from ch1ago/my_config.rb
Created April 10, 2013 14:44
Show Gist options
  • Save sam452/5355242 to your computer and use it in GitHub Desktop.
Save sam452/5355242 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