Sprankelprachtig aan/afmeldsysteem

activities_controller.rb 2.3KB

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