ぼざクリ タグ広場 https://hub.nizika.monster
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.
 
 
 
 
 
 

35 lines
966 B

  1. class WikiPagesController < ApplicationController
  2. def show
  3. wiki_page = WikiPage.find_by(title: params[:title])
  4. if wiki_page
  5. render plain: wiki_page.markdown
  6. else
  7. head :not_found
  8. end
  9. end
  10. def create
  11. return head :unauthorized unless current_user
  12. wiki_page = WikiPage.new(title: params[:title], tag_id: params[:tag_id], created_user: current_user, updated_user: current_user)
  13. wiki_page.markdown = params[:markdown], user: current_user
  14. if wiki_page.save
  15. render json: wiki_page, status: :created
  16. else
  17. render json: { errors: wiki_page.errors.full_messages }, status: :unprocessable_entity
  18. end
  19. end
  20. def update
  21. return head :unauthorized unless current_user
  22. wiki_page = WikiPage.find(params[:id])
  23. return head :not_found unless wiki_pages
  24. wiki_page.updated_user = current_user
  25. wiki_page.markdown = params[:markdown], user: current_user
  26. wiki_page.save!
  27. head :ok
  28. end
  29. end