Sprankelprachtig aan/afmeldsysteem

groups_controller.rb 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. class GroupsController < ApplicationController
  2. include GroupsHelper
  3. before_action :require_admin!, only: [:index]
  4. before_action :require_membership!, only: [:show]
  5. before_action :require_leader!, only: [:edit, :update, :destroy]
  6. before_action :set_group, only: [:show, :edit, :update, :destroy]
  7. # GET /groups
  8. # GET /groups.json
  9. def index
  10. @groups = Group.all
  11. end
  12. def user_groups
  13. @groups = current_person.groups
  14. end
  15. # GET /groups/1
  16. # GET /groups/1.json
  17. def show
  18. end
  19. # GET /groups/new
  20. def new
  21. @group = Group.new
  22. end
  23. # GET /groups/1/edit
  24. def edit
  25. end
  26. # POST /groups
  27. # POST /groups.json
  28. def create
  29. @group = Group.new(group_params)
  30. respond_to do |format|
  31. if @group.save
  32. format.html {
  33. redirect_to @group
  34. flash_message(:info, 'Group was successfully created.')
  35. }
  36. format.json { render :show, status: :created, location: @group }
  37. else
  38. format.html { render :new }
  39. format.json { render json: @group.errors, status: :unprocessable_entity }
  40. end
  41. end
  42. end
  43. # PATCH/PUT /groups/1
  44. # PATCH/PUT /groups/1.json
  45. def update
  46. respond_to do |format|
  47. if @group.update(group_params)
  48. format.html {
  49. redirect_to @group
  50. flash_message(:info, 'Group was successfully updated.')
  51. }
  52. format.json { render :show, status: :ok, location: @group }
  53. else
  54. format.html { render :edit }
  55. format.json { render json: @group.errors, status: :unprocessable_entity }
  56. end
  57. end
  58. end
  59. # DELETE /groups/1
  60. # DELETE /groups/1.json
  61. def destroy
  62. @group.destroy
  63. respond_to do |format|
  64. format.html {
  65. redirect_to groups_url
  66. flash_message(:info, 'Group was successfully destroyed.')
  67. }
  68. format.json { head :no_content }
  69. end
  70. end
  71. private
  72. # Use callbacks to share common setup or constraints between actions.
  73. def set_group
  74. @group = Group.find(params[:id])
  75. end
  76. # Never trust parameters from the scary internet, only allow the white list through.
  77. def group_params
  78. params.require(:group).permit(:name)
  79. end
  80. end