hide protected keys from config

This commit is contained in:
wvengen 2014-06-21 18:01:02 +02:00
parent 90f60595e6
commit 429e111db4
2 changed files with 4 additions and 1 deletions

View File

@ -1,12 +1,14 @@
module Admin::ConfigsHelper
# Returns form input for configuration key.
# For configuration keys that contain a {Hash}, {ActiveView::Helpers::FormBuilder#fields_for fields_for} can be used.
# When the key is not {FoodsoftConfig#allowed_key? allowed}, +nil+ is returned.
# @param form [ActionView::Helpers::FormBuilder] Form object.
# @param key [Symbol, String] Configuration key.
# @param options [Hash] Options passed to the form builder.
# @option options [Boolean] :required Wether field is shown as required (default not).
# @return [String] Form input for configuration key.
def config_input(form, key, options = {}, &block)
return unless @cfg.allowed_key? key
options[:label] = config_input_label(form, key)
options[:required] ||= false
options[:input_html] ||= {}
@ -36,6 +38,7 @@ module Admin::ConfigsHelper
# @see config_input
# @todo find out how to pass +checked_value+ and +unchecked_value+ to +input_field+
def config_input_field(form, key, options = {})
return unless @cfg.allowed_key? :key
config_input_field_options form, key, options
config_input_tooltip_options form, key, options
if options[:as] == :boolean

View File

@ -130,7 +130,7 @@ class FoodsoftConfig
# @return [Boolean] Whether this key may be set in the database
def allowed_key?(key)
# fast check for keys without nesting
return !self.config[:protected].keys.include?(key)
return !self.config[:protected].keys.include?(key.to_s)
# @todo allow to check nested keys as well
end