Module: HomePage::FormHelper

Defined in:
app/helpers/home_page/form_helper.rb

Instance Method Summary collapse

Instance Method Details

#setting_input(f, var, options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/home_page/form_helper.rb', line 3

def setting_input(f, var, options = {})
  required = options.delete(:required) || false
  label = options.delete(:label)
  
  default = Setting.defaults[var]
  hint_value = default.is_a?(Array) || default.is_a?(Hash) ? default.to_json : default.inspect
  value = @settings[var].try(:value)
  value = if value.nil?
    value
  else
    default.is_a?(Array) || default.is_a?(Hash) ? value.to_json : value
  end
  
  f.input(
    var, label: label || t("settings.vars.#{var}"), input_html: { id: var.gsub(/\./, '_'), value: value },
    hint: Setting.defaults[var].nil? ? nil : t('settings.index.default_value', value: hint_value),
    required: required
  )
end