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.

45 lines
968 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. site_terms
  11. open_registrations
  12. closed_registrations_message
  13. ).freeze
  14. BOOLEAN_SETTINGS = %w(open_registrations).freeze
  15. def edit
  16. @settings = Setting.all_as_records
  17. end
  18. def update
  19. settings_params.each do |key, value|
  20. setting = Setting.where(var: key).first_or_initialize(var: key)
  21. setting.update(value: value_for_update(key, value))
  22. end
  23. flash[:notice] = 'Success!'
  24. redirect_to edit_admin_settings_path
  25. end
  26. private
  27. def settings_params
  28. params.permit(ADMIN_SETTINGS)
  29. end
  30. def value_for_update(key, value)
  31. if BOOLEAN_SETTINGS.include?(key)
  32. value == 'true'
  33. else
  34. value
  35. end
  36. end
  37. end
  38. end