Sprankelprachtig aan/afmeldsysteem

activities_controller.rb 2.1KB

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