ticket_articles_controller.rb 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. class TicketArticlesController < ApplicationController
  2. before_filter :authentication_check
  3. # GET /articles
  4. def index
  5. @articles = Ticket::Article.all
  6. render :json => @articles
  7. end
  8. # GET /articles/1
  9. def show
  10. @article = Ticket::Article.find(params[:id])
  11. render :json => @article
  12. end
  13. # POST /articles
  14. def create
  15. @article = Ticket::Article.new(params[:ticket_article])
  16. @article.created_by_id = current_user.id
  17. # find attachments in upload cache
  18. @article['attachments'] = Store.list(
  19. :object => 'UploadCache::TicketZoom::' + current_user.id.to_s,
  20. :o_id => @article.ticket_id
  21. )
  22. if @article.save
  23. # remove attachments from upload cache
  24. Store.remove(
  25. :object => 'UploadCache::TicketZoom::' + current_user.id.to_s,
  26. :o_id => @article.ticket_id
  27. )
  28. render :json => @article, :status => :created
  29. else
  30. render :json => @article.errors, :status => :unprocessable_entity
  31. end
  32. end
  33. # PUT /articles/1
  34. def update
  35. @article = Ticket::Article.find(params[:id])
  36. if @article.update_attributes(params[:ticket_article])
  37. render :json => @article, :status => :ok
  38. else
  39. render :json => @article.errors, :status => :unprocessable_entity
  40. end
  41. end
  42. # DELETE /articles/1
  43. def destroy
  44. @article = Ticket::Article.find(params[:id])
  45. @article.destroy
  46. head :ok
  47. end
  48. end