Class: BetaFeature::SettingsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- BetaFeature::SettingsController
- Defined in:
- app/controllers/beta_feature/settings_controller.rb
Instance Method Summary collapse
-
#show ⇒ Object
GET /beta_feature/:object_class/:object_id/setting.
-
#update ⇒ Object
PUT /beta_feature/:object_class/:object_id/setting Params: { betas: { custom_domain: true, dark_mode: false, ux_improvement_2021: true } }.
Instance Method Details
#show ⇒ Object
GET /beta_feature/:object_class/:object_id/setting
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/controllers/beta_feature/settings_controller.rb', line 13 def show betas = {} BetaFeature.all_betas.keys.map do |key| betas[key] = @object.all_betas.include?(key) ? true : false end render json: { object_class: @object_class, object_id: @object_id, betas: betas } end |
#update ⇒ Object
PUT /beta_feature/:object_class/:object_id/setting Params: {
betas: {
custom_domain: true,
dark_mode: false,
ux_improvement_2021: true
}
}
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/controllers/beta_feature/settings_controller.rb', line 35 def update betas = params.permit![:betas] enabled_betas = betas.select {|k, v| v.to_s == "true"}.keys disabled_betas = betas.select {|k, v| v.to_s == "false"}.keys @object.enable_beta!(*enabled_betas) if enabled_betas.present? @object.remove_beta!(*disabled_betas) if disabled_betas.present? render json: { object_class: @object_class, object_id: @object_id, betas: @object.all_betas } end |