You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
991 B

  1. # frozen_string_literal: true
  2. module Admin
  3. class RulesController < BaseController
  4. before_action :set_rule, except: [:index, :create]
  5. def index
  6. authorize :rule, :index?
  7. @rules = Rule.ordered
  8. @rule = Rule.new
  9. end
  10. def create
  11. authorize :rule, :create?
  12. @rule = Rule.new(resource_params)
  13. if @rule.save
  14. redirect_to admin_rules_path
  15. else
  16. @rules = Rule.ordered
  17. render :index
  18. end
  19. end
  20. def edit
  21. authorize @rule, :update?
  22. end
  23. def update
  24. authorize @rule, :update?
  25. if @rule.update(resource_params)
  26. redirect_to admin_rules_path
  27. else
  28. render :edit
  29. end
  30. end
  31. def destroy
  32. authorize @rule, :destroy?
  33. @rule.discard
  34. redirect_to admin_rules_path
  35. end
  36. private
  37. def set_rule
  38. @rule = Rule.find(params[:id])
  39. end
  40. def resource_params
  41. params.require(:rule).permit(:text, :priority)
  42. end
  43. end
  44. end