Class: Lightning::FeatureOptInsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/lightning/feature_opt_ins_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/lightning/feature_opt_ins_controller.rb', line 6

def create
  @feature = Feature.find(params[:feature_id])
  entity_ids = params[:feature_opt_in][:entity_id].split(",")
  entity_class = params[:feature_opt_in][:entity_type].constantize

  entity_ids.each do |entity_id|
    entity = entity_class.find(entity_id)
    @feature.feature_opt_ins.find_or_create_by!(entity_id: entity.id, entity_type: entity_class.to_s)
  end

  flash[:notice] = "Permissions has been created!"
  redirect_to @feature
rescue => e
  flash[:notice] = "Failed to opt in some entities: #{e.message}"
  redirect_to @feature
end

#destroyObject



23
24
25
26
27
28
# File 'app/controllers/lightning/feature_opt_ins_controller.rb', line 23

def destroy
  @feature = Feature.find(params[:feature_id])
  @feature_opt_in = @feature.feature_opt_ins.find(params[:id])
  @feature_opt_in.destroy
  redirect_to @feature, notice: 'Feature permission was successfully destroyed.'
end