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 create
  11. authorize :account_warning_preset, :create?
  12. @warning_preset = AccountWarningPreset.new(warning_preset_params)
  13. if @warning_preset.save
  14. redirect_to admin_warning_presets_path
  15. else
  16. @warning_presets = AccountWarningPreset.alphabetic
  17. render :index
  18. end
  19. end
  20. def edit
  21. authorize @warning_preset, :update?
  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