You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

30 lines
610 B

  1. class ThreadsController < ApplicationController
  2. # GET /api/threads
  3. def index
  4. threads = Topic.order(updated_at: :desc)
  5. render json: threads
  6. end
  7. # GET /api/threads/:id
  8. def show
  9. thread = Topic.find(params[:id])
  10. render json: thread
  11. end
  12. # POST /api/threads
  13. def create
  14. thread = Topic.new(thread_params)
  15. if thread.save
  16. render json: thread, status: :created
  17. else
  18. render json: { errors: thread.errors.full_messages }, status: :unprocessable_entity
  19. end
  20. end
  21. private
  22. def thread_params
  23. params.require(:thread).permit(:title, :description)
  24. end
  25. end