36 lines
652 B
Ruby
36 lines
652 B
Ruby
class PostsController < ApplicationController
|
|
# GET /posts
|
|
# GET /posts.json
|
|
def index
|
|
@posts = Post.all
|
|
end
|
|
|
|
# GET /posts/1
|
|
# GET /posts/1.json
|
|
def show
|
|
@post = Post.find(params[:id])
|
|
end
|
|
|
|
# POST /posts
|
|
# POST /posts.json
|
|
def create
|
|
@post = Post.new(post_params)
|
|
|
|
if @post.save
|
|
render :show, status: :created, location: @post
|
|
else
|
|
render json: @post.errors, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
private
|
|
|
|
# Only allow a list of trusted parameters through.
|
|
def post_params
|
|
{
|
|
user: current_user,
|
|
**params.require(:post).permit(:content, :quoted_post_id)
|
|
}
|
|
end
|
|
end
|