topic_categories_controller.rb 857 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. class Admin::TopicCategoriesController < Admin::ApplicationController
  2. def index
  3. render json: TopicCategory.all
  4. end
  5. def create
  6. topic_category = TopicCategory.new(topic_category_params)
  7. if topic_category.save
  8. render json: topic_category
  9. else
  10. render json: topic_category.errors, status: 500
  11. end
  12. end
  13. def destroy
  14. begin
  15. TopicCategory.destroy(params[:id])
  16. render json: { id: params[:id] }
  17. rescue => e
  18. render text: e.message, status: 500
  19. end
  20. end
  21. def update
  22. topic_category = TopicCategory.find(params[:id])
  23. if topic_category.update_attributes(topic_category_params)
  24. render json: topic_category
  25. else
  26. render json: topic_category.errors, status: 500
  27. end
  28. end
  29. private
  30. def topic_category_params
  31. params.require(:topic_category).permit(:name)
  32. end
  33. end