How to implement a singleton model

后端 未结 13 1322
余生分开走
余生分开走 2020-12-24 12:36

I have a site in rails and want to have site-wide settings. One part of my app can notify the admin by SMS if a specific event happens. This is an example of a feature that

相关标签:
13条回答
  • 2020-12-24 13:03
    class Constant < ActiveRecord::Base
      after_initialize :readonly!
    
      def self.const_missing(name)
        first[name.to_s.downcase]
      end
    end
    

    Constant::FIELD_NAME

    0 讨论(0)
提交回复
热议问题