|
@@ -0,0 +1,81 @@
|
|
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
|
+
|
|
7
|
+ # GET /groups/:id/activities
|
|
8
|
+ # GET /activities.json
|
|
9
|
+ def index
|
|
10
|
+ @activities = @group.activities
|
|
11
|
+ end
|
|
12
|
+
|
|
13
|
+ # GET /activities/1
|
|
14
|
+ # GET /activities/1.json
|
|
15
|
+ def show
|
|
16
|
+ end
|
|
17
|
+
|
|
18
|
+ # GET /activities/new
|
|
19
|
+ def new
|
|
20
|
+ @activity = Activity.new
|
|
21
|
+ end
|
|
22
|
+
|
|
23
|
+ # GET /activities/1/edit
|
|
24
|
+ def edit
|
|
25
|
+ end
|
|
26
|
+
|
|
27
|
+ # POST /activities
|
|
28
|
+ # POST /activities.json
|
|
29
|
+ def create
|
|
30
|
+ @activity = Activity.new(activity_params)
|
|
31
|
+
|
|
32
|
+ respond_to do |format|
|
|
33
|
+ if @activity.save
|
|
34
|
+ format.html { redirect_to @activity, notice: 'Activity was successfully created.' }
|
|
35
|
+ format.json { render :show, status: :created, location: @activity }
|
|
36
|
+ else
|
|
37
|
+ format.html { render :new }
|
|
38
|
+ format.json { render json: @activity.errors, status: :unprocessable_entity }
|
|
39
|
+ end
|
|
40
|
+ end
|
|
41
|
+ end
|
|
42
|
+
|
|
43
|
+ # PATCH/PUT /activities/1
|
|
44
|
+ # PATCH/PUT /activities/1.json
|
|
45
|
+ def update
|
|
46
|
+ respond_to do |format|
|
|
47
|
+ if @activity.update(activity_params)
|
|
48
|
+ format.html { redirect_to @activity, notice: 'Activity was successfully updated.' }
|
|
49
|
+ format.json { render :show, status: :ok, location: @activity }
|
|
50
|
+ else
|
|
51
|
+ format.html { render :edit }
|
|
52
|
+ format.json { render json: @activity.errors, status: :unprocessable_entity }
|
|
53
|
+ end
|
|
54
|
+ end
|
|
55
|
+ end
|
|
56
|
+
|
|
57
|
+ # DELETE /activities/1
|
|
58
|
+ # DELETE /activities/1.json
|
|
59
|
+ def destroy
|
|
60
|
+ @activity.destroy
|
|
61
|
+ respond_to do |format|
|
|
62
|
+ format.html { redirect_to activities_url, notice: 'Activity was successfully destroyed.' }
|
|
63
|
+ format.json { head :no_content }
|
|
64
|
+ end
|
|
65
|
+ end
|
|
66
|
+
|
|
67
|
+ private
|
|
68
|
+ # Use callbacks to share common setup or constraints between actions.
|
|
69
|
+ def set_activity
|
|
70
|
+ @activity = Activity.find(params[:id])
|
|
71
|
+ end
|
|
72
|
+
|
|
73
|
+ def set_group
|
|
74
|
+ @group = Group.find(params[:group_id])
|
|
75
|
+ end
|
|
76
|
+
|
|
77
|
+ # Never trust parameters from the scary internet, only allow the white list through.
|
|
78
|
+ def activity_params
|
|
79
|
+ params.fetch(:activity, {})
|
|
80
|
+ end
|
|
81
|
+end
|