Class: PostsController

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

Overview

The post controller

Instance Method Summary collapse

Methods inherited from ApplicationController

#system

Instance Method Details

#createObject

Create a new post


26
27
28
29
# File 'app/controllers/posts_controller.rb', line 26

def create
  post = Post.new
  post.attributes = params.require(:post).permit(:topic_id, :user_id, :content)
end

#destroyObject

Destroy a post


37
38
39
# File 'app/controllers/posts_controller.rb', line 37

def destroy
  @post.destroy
end

#indexObject

Lists all the posts


16
17
18
# File 'app/controllers/posts_controller.rb', line 16

def index
  render json: @topic.posts.all
end

#showObject

Shows a post


21
22
23
# File 'app/controllers/posts_controller.rb', line 21

def show
  render json: @post
end

#updateObject

Update a post


32
33
34
# File 'app/controllers/posts_controller.rb', line 32

def update
  @post.attributes = params.require(:post).permit(:topic_id, :user_id, :content)
end