Closed kausters closed 3 years ago
You wants type
for write admin interface?
I strongly recommend you follow the README guides to write Setting form, write form control HTML template for each keys, not use a loop to generate.
<%= form_for(Setting.new, url: admin_settings_path) do |f| %>
<div class="form-group">
<label class="control-label">Host</label>
<%= f.text_field :host, value: Setting.host, class: "form-control", placeholder: "http://localhost" %>
</div>
<div class="form-group form-checkbox">
<label>
<%= f.check_box :captcha_enable, checked: Setting.captcha_enable? %>
Enable/Disable Captcha
</label>
</div>
<div class="form-group">
<label class="control-label">Admin Emails</label>
<%= f.text_area :admin_emails, value: Setting.admin_emails.join("\n"), class: "form-control" %>
</div>
<div class="form-group">
<label class="control-label">Notification options</label>
<%= f.text_area :notification_options, value: YAML.dump(Setting.notification_options), class: "form-control", style: "height: 180px;" %>
<div class="form-text">
Use YAML format to config the SMTP_html
</details>
<% end %>
After that, you will get a better setting interface like this:
For the site I'm building, the settings are internal admin stuff with basic fields, not an artisanal user settings page. Regardless, everything in the screenshots could just as well be abstracted away in a generator/loop — groups, labels, placeholders, extra text etc. And as a programmer I want to automate my work, and not being able to add extra fields to Settings records and then access them is a major limitation, especially if I need to add more settings or change the field template in the future — customizing a view with the same things over and over feels counter-productive.
I will try to implement this.
Hi, I had the same problem here! I created a super simple singleton_method (no test 👎) here: https://github.com/huacnlee/rails-settings-cached/compare/master...svarione:master which adds a #{key}_setting_type method which returns a symbol
get_field
method can do that:
Setting.get_field("host")
=> { key: "host", type: :string, default: "http://example.com", readonly: true }
Hi!
I'm trying to update to 2.0. Previously I had added a "format" field (
enum
of:boolean
,:string
, etc) to my Setting model so I could render the appropriate form control automatically. I was glad to see that now there is atype
property in thefield
declaration but I can't find a way to access this property in my form view.Any tips? Thanks and congratulations on the update!