warning_presets_controller.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # frozen_string_literal: true
  2. module Admin
  3. class WarningPresetsController < BaseController
  4. before_action :set_warning_preset, except: [:index, :create]
  5. def index
  6. authorize :account_warning_preset, :index?
  7. @warning_presets = AccountWarningPreset.alphabetic
  8. @warning_preset = AccountWarningPreset.new
  9. end
  10. def edit
  11. authorize @warning_preset, :update?
  12. end
  13. def create
  14. authorize :account_warning_preset, :create?
  15. @warning_preset = AccountWarningPreset.new(warning_preset_params)
  16. if @warning_preset.save
  17. redirect_to admin_warning_presets_path
  18. else
  19. @warning_presets = AccountWarningPreset.alphabetic
  20. render :index
  21. end
  22. end
  23. def update
  24. authorize @warning_preset, :update?
  25. if @warning_preset.update(warning_preset_params)
  26. redirect_to admin_warning_presets_path
  27. else
  28. render :edit
  29. end
  30. end
  31. def destroy
  32. authorize @warning_preset, :destroy?
  33. @warning_preset.destroy!
  34. redirect_to admin_warning_presets_path
  35. end
  36. private
  37. def set_warning_preset
  38. @warning_preset = AccountWarningPreset.find(params[:id])
  39. end
  40. def warning_preset_params
  41. params.require(:account_warning_preset).permit(:title, :text)
  42. end
  43. end
  44. end