Class: ErrorRadar::SettingsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- ErrorRadar::SettingsController
- Defined in:
- app/controllers/error_radar/settings_controller.rb
Constant Summary collapse
- CHATWORK_KEYS =
%w[chatwork_api_token chatwork_room_id chatwork_notify_sources].freeze
Instance Method Summary collapse
Instance Method Details
#show ⇒ Object
9 10 11 12 13 14 15 |
# File 'app/controllers/error_radar/settings_controller.rb', line 9 def show @settings = CHATWORK_KEYS.each_with_object({}) do |key, h| h[key] = Setting.get(key) end # notify_sources is stored as an array; join for the textarea @settings['chatwork_notify_sources'] = Array(@settings['chatwork_notify_sources']).join("\n") end |
#update ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/controllers/error_radar/settings_controller.rb', line 17 def update CHATWORK_KEYS.each do |key| value = settings_params[key] next if value.nil? if key == 'chatwork_notify_sources' lines = value.split(/[\n,]+/).map(&:strip).reject(&:empty?) Setting.set(key, lines) else Setting.set(key, value.strip.presence) end end redirect_to settings_path, notice: 'Settings saved.' end |