Class: Detour::FlaggableFlagsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Detour::FlaggableFlagsController
- Defined in:
- app/controllers/detour/flaggable_flags_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/controllers/detour/flaggable_flags_controller.rb', line 11 def create @feature = Detour::Feature.find_by_name! feature_name ids = params[:ids].split(",") @errors = [] Detour::Feature.transaction do begin ids.each do |id| flaggable = flaggable_class.flaggable_find! id flag = @feature.send("#{flaggable_type}_#{flag_type.pluralize}").new flaggable: flaggable unless flag.save @errors.concat flag.errors. end end rescue ActiveRecord::RecordNotFound => e @errors << e. end if @errors.any? raise ActiveRecord::Rollback end end if @errors.empty? flash[:notice] = render :success else render :error end end |
#destroy ⇒ Object
43 44 45 46 47 48 49 |
# File 'app/controllers/detour/flaggable_flags_controller.rb', line 43 def destroy feature = Detour::Feature.find_by_name!(feature_name) @flag = feature.send("#{flag_type}_flags").find(params[:id]) @flag.destroy flash[:notice] = "#{feature_name} #{flag_noun} for #{flaggable_class} #{@flag.flaggable.send flaggable_class.detour_flaggable_find_by} has been deleted." redirect_to send("#{flag_type}_flags_path", feature.name, flaggable_type) end |
#index ⇒ Object
6 7 8 9 |
# File 'app/controllers/detour/flaggable_flags_controller.rb', line 6 def index feature = Detour::Feature.find_by_name!(feature_name) @flags = feature.send("#{flag_type}_flags").where(flaggable_type: flaggable_class.to_s) end |