-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathlearning_path_topics_controller.rb
More file actions
92 lines (79 loc) · 2.82 KB
/
Copy pathlearning_path_topics_controller.rb
File metadata and controls
92 lines (79 loc) · 2.82 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
class LearningPathTopicsController < ApplicationController
before_action -> { ensure_feature_enabled('learning_paths') }
before_action :set_topic, only: %i[show edit update destroy]
before_action :set_breadcrumbs
include SearchableIndex
def index
respond_to do |format|
format.html
format.json
format.json_api { render({ json: @learning_path_topics }.merge(api_collection_properties)) }
end
end
def show
respond_to do |format|
format.html
# format.json
# format.json_api { render json: @learning_path_topic }
end
end
# GET /topics/new
def new
authorize LearningPathTopic
@learning_path_topic = LearningPathTopic.new
end
def edit
authorize @learning_path_topic
end
def create
authorize LearningPathTopic
@learning_path_topic = LearningPathTopic.new(topic_params)
@learning_path_topic.user = current_user
@learning_path_topic.space = current_space
respond_to do |format|
if @learning_path_topic.save
@learning_path_topic.create_activity :create, owner: current_user
format.html { redirect_to @learning_path_topic, notice: 'Topic was successfully created.' }
# format.json { render :show, status: :created, location: @learning_path_topic }
else
format.html { render :new }
# format.json { render json: @learning_path_topic.errors, status: :unprocessable_entity }
end
end
end
def update
authorize @learning_path_topic
respond_to do |format|
if @learning_path_topic.update(topic_params)
@learning_path_topic.create_activity(:update, owner: current_user) if @learning_path_topic.log_update_activity?
format.html { redirect_to @learning_path_topic, notice: 'Topic was successfully updated.' }
# format.json { render :show, status: :ok, location: @learning_path_topic }
else
format.html { render :edit }
# format.json { render json: @learning_path_topic.errors, status: :unprocessable_entity }
end
end
end
def destroy
authorize @learning_path_topic
@learning_path_topic.create_activity :destroy, owner: current_user
@learning_path_topic.destroy
respond_to do |format|
format.html { redirect_to learning_path_topics_path, notice: 'Topic was successfully destroyed.' }
# format.json { head :no_content }
end
end
private
def set_topic
@learning_path_topic = LearningPathTopic.find(params[:id])
end
def topic_params
params.require(:learning_path_topic).permit(
:title, :description, :difficulty_level, { keywords: [] }, { material_ids: [] }, { event_ids: [] },
{ items_attributes: [:id, :resource_type, :resource_id, :order, :comment, :_destroy] })
end
def add_base_breadcrumbs(_)
super('learning_paths')
add_index_breadcrumb(controller_name, 'Topics')
end
end