Sprankelprachtig aan/afmeldsysteem

groups_controller.rb 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 { redirect_to @group, notice: 'Group was successfully created.' }
  33. format.json { render :show, status: :created, location: @group }
  34. else
  35. format.html { render :new }
  36. format.json { render json: @group.errors, status: :unprocessable_entity }
  37. end
  38. end
  39. end
  40. # PATCH/PUT /groups/1
  41. # PATCH/PUT /groups/1.json
  42. def update
  43. respond_to do |format|
  44. if @group.update(group_params)
  45. format.html { redirect_to @group, notice: 'Group was successfully updated.' }
  46. format.json { render :show, status: :ok, location: @group }
  47. else
  48. format.html { render :edit }
  49. format.json { render json: @group.errors, status: :unprocessable_entity }
  50. end
  51. end
  52. end
  53. # DELETE /groups/1
  54. # DELETE /groups/1.json
  55. def destroy
  56. @group.destroy
  57. respond_to do |format|
  58. format.html { redirect_to groups_url, notice: 'Group was successfully destroyed.' }
  59. format.json { head :no_content }
  60. end
  61. end
  62. private
  63. # Use callbacks to share common setup or constraints between actions.
  64. def set_group
  65. @group = Group.find(params[:id])
  66. end
  67. # Never trust parameters from the scary internet, only allow the white list through.
  68. def group_params
  69. params.fetch(:group, {})
  70. end
  71. end