Class: TopicsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/topics_controller.rb

Overview

The topics controller

Instance Method Summary collapse

Methods inherited from ApplicationController

#system

Instance Method Details

#createObject

Create a topic


27
28
29
30
# File 'app/controllers/topics_controller.rb', line 27

def create
  topic = Topic.new
  topic.attributes = params.require(:topic).permit(:forum_id, :user_id, :name)
end

#destroyObject

Destroy a topic


38
39
40
# File 'app/controllers/topics_controller.rb', line 38

def destroy
  @topic.destroy
end

#indexObject

Show all topics


17
18
19
# File 'app/controllers/topics_controller.rb', line 17

def index
  render json: @forum.topics.all
end

#showObject

Show a single topic


22
23
24
# File 'app/controllers/topics_controller.rb', line 22

def show
  render json: @topic
end

#updateObject

Update a topic


33
34
35
# File 'app/controllers/topics_controller.rb', line 33

def update
  @topic.attributes = params.require(:topic).permit(:forum_id, :user_id, :name)
end