Sprankelprachtig aan/afmeldsysteem

people_controller.rb 2.1KB

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