You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
951 B

  1. # frozen_string_literal: true
  2. module Admin
  3. class SettingsController < BaseController
  4. ADMIN_SETTINGS = %w(
  5. site_contact_username
  6. site_contact_email
  7. site_title
  8. site_description
  9. site_extended_description
  10. open_registrations
  11. closed_registrations_message
  12. ).freeze
  13. BOOLEAN_SETTINGS = %w(open_registrations).freeze
  14. def edit
  15. @settings = Setting.all_as_records
  16. end
  17. def update
  18. settings_params.each do |key, value|
  19. setting = Setting.where(var: key).first_or_initialize(var: key)
  20. setting.update(value: value_for_update(key, value))
  21. end
  22. flash[:notice] = 'Success!'
  23. redirect_to edit_admin_settings_path
  24. end
  25. private
  26. def settings_params
  27. params.permit(ADMIN_SETTINGS)
  28. end
  29. def value_for_update(key, value)
  30. if BOOLEAN_SETTINGS.include?(key)
  31. value == 'true'
  32. else
  33. value
  34. end
  35. end
  36. end
  37. end