This repository was archived by the owner on Dec 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtopics_controller.rb
More file actions
97 lines (85 loc) · 2.72 KB
/
topics_controller.rb
File metadata and controls
97 lines (85 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
class TopicsController < ApplicationController
before_action :authenticate_user!
load_and_authorize_resource
# GET /topics
# GET /topics.json
def index
@approved_topics = Topic.approved.not_completed
@pending_topics = Topic.pending_approval.not_completed
@completed_topics = Topic.completed
@topic_sections = [:approved_topics,
:pending_topics,
:completed_topics]
@headings = [
:student_id,
:title,
:description,
:proposed_date,
:completed_date
].map{|h| Topic.human_attribute_name(h)}
@headings.push I18n.t('.actions', default: I18n.t("helpers.actions"))
@headings.push "Admin Actions" if current_user.is_admin?
end
# GET /topics/1
# GET /topics/1.json
def show
@student = @topic.student
end
# GET /topics/new
def new
end
# GET /topics/1/edit
def edit
end
# POST /topics
# POST /topics.json
def create
@topic.student = current_user
respond_to do |format|
if @topic.save
format.html { redirect_to @topic, notice: 'Topic was successfully created.' }
format.mobile { redirect_to @topic, notice: 'Topic was successfully created.' }
format.json { render :show, status: :created, location: @topic }
else
format.html { render :new }
format.mobile { render :new }
format.json { render json: @topic.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /topics/1
# PATCH/PUT /topics/1.json
def update
respond_to do |format|
if @topic.update(topic_params)
format.html { redirect_to @topic, notice: 'Topic was successfully updated.' }
format.mobile { redirect_to @topic, notice: 'Topic was successfully updated.' }
format.json { render :show, status: :ok, location: @topic }
end
end
end
# DELETE /topics/1
# DELETE /topics/1.json
def destroy
respond_to do |format|
if @topic.destroy
format.html { redirect_to topics_url, notice: 'Topic was successfully destroyed.' }
format.mobile{ redirect_to topics_url, notice: 'Topic was successfully destroyed.' }
format.json { head :no_content }
end
end
end
def approve
return redirect_to topics_url if @topic.approve!
redirect_to topics_url, notice: 'Problem approving topic'
end
def complete
return redirect_to topics_url if @topic.complete!
redirect_to topics_url, notice: 'Problem completing topic'
end
private
# Never trust parameters from the scary internet, only allow the white list through.
def topic_params
params.require(:topic).permit(:title, :description, :proposed_date)
end
end