topics_controller.rb 580 B

123456789101112131415161718192021222324252627282930
  1. class Admin::TopicsController < Admin::ApplicationController
  2. layout "admin"
  3. def destroy
  4. begin
  5. Topic.destroy(params[:id])
  6. render json: { id: params[:id] }
  7. rescue => e
  8. render text: e.message, status: 500
  9. end
  10. end
  11. def create
  12. topic_set = TopicSet.find(params.require(:topic).delete(:topic_set_id))
  13. topic = topic_set.topics.build(topic_params)
  14. if topic.save
  15. render json: topic
  16. else
  17. render json: topic.errors, status: 500
  18. end
  19. end
  20. private
  21. def topic_params
  22. params.require(:topic).permit(:name)
  23. end
  24. end