Files
postter/app/controllers/posts_controller.rb
2022-02-27 23:08:47 -03:00

33 lines
620 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
params.require(:post).permit(:content, :user_id, :quoted_post_id)
end
end