huacnlee / rails-settings-cached

Global settings for your Rails application.
Other
1.06k stars 202 forks source link

Adds an optional metadata to fields #209

Closed anujmiddha closed 3 years ago

anujmiddha commented 3 years ago

We might need to add certain metadata with each field. This pull request adds this support.

For example, we can add description with different fields, which can be shown on the admin page for updating the fields.

field :host, default: "http://example.com", validates: { presence: true }, metadata: { description: "Host url" }
anujmiddha commented 3 years ago

210 Adds support for metadata

huacnlee commented 3 years ago

Version 2.7.x has allows you to add any options for field.

https://github.com/huacnlee/rails-settings-cached/releases/tag/v2.7.0

class Setting
  field :my_key, type: :string, description: "Hello world", placeholder: "My key"
end

And the you can use get_field to get description

field = Setting.get_field("my_key")
field[:options]
=> { description: "Hello world", placeholder: "My key" }