README.md in rails-settings-cached-2.7.0 vs README.md in rails-settings-cached-2.7.1

- old
+ new

@@ -32,11 +32,11 @@ # cache_prefix { "v1" } scope :application do field :app_name, default: "Rails Settings", validates: { presence: true, length: { in: 2..20 } } field :host, default: "http://example.com", readonly: true - field :default_locale, default: "zh-CN", validates: { presence: true, inclusion: { in: %w[zh-CN en jp] } }, option_values: %w[en zh-CN] + field :default_locale, default: "zh-CN", validates: { presence: true, inclusion: { in: %w[zh-CN en jp] } }, option_values: %w[en zh-CN jp], help_text: "Bla bla ..." field :admin_emails, type: :array, default: %w[admin@rubyonrails.org] # lambda default value field :welcome_message, type: :string, default: -> { "welcome to #{self.app_name}" }, validates: { length: { maximum: 255 } } # Override array separator, default: /[\n,]/ split with \n or comma. @@ -44,25 +44,27 @@ end scope :limits do field :user_limits, type: :integer, default: 20 field :exchange_rate, type: :float, default: 0.123 - field :captcha_enable, type: :boolean, default: true, group: :limits + field :captcha_enable, type: :boolean, default: true end field :notification_options, type: :hash, default: { send_all: true, logging: true, sender_email: "foo@bar.com" - }, group: :advanced + } field :readonly_item, type: :integer, default: 100, readonly: true end ``` You must use the `field` method to statement the setting keys, otherwise you can't use it. +The `scope` method allows you to group the keys for admin UI. + Now just put that migration in the database with: ```bash $ rails db:migrate ``` @@ -147,16 +149,19 @@ # Get readonly keys Setting.readonly_keys => ["host", "readonly_item"] -# Get options of field +# Get field Setting.get_field("host") => { scope: :application, key: "host", type: :string, default: "http://example.com", readonly: true } Setting.get_field("app_name") => { scope: :application, key: "app_name", type: :string, default: "Rails Settings", readonly: false } Setting.get_field(:user_limits) => { scope: :limits, key: "user_limits", type: :integer, default: 20, readonly: false } +# Get field options +Setting.get_field("default_locale")[:options] +=> { option_values: %w[en zh-CN jp], help_text: "Bla bla ..." } ``` #### Get All defined fields > version 2.7.0+