translations_controller.rb 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. class TranslationsController < ApplicationController
  2. before_filter :authentication_check, :except => [:load]
  3. # GET /translations/:lang
  4. def load
  5. translations = Translation.where( :locale => params[:locale] )
  6. list = []
  7. translations.each { |item|
  8. data = [
  9. item.id,
  10. item.source,
  11. item.target,
  12. ]
  13. list.push data
  14. }
  15. render :json => list
  16. end
  17. # GET /translations
  18. def index
  19. @translations = Translation.all
  20. render :json => @translations
  21. end
  22. # GET /translations/1
  23. def show
  24. @translation = Translation.find(params[:id])
  25. render :json => @translation
  26. end
  27. # POST /translations
  28. def create
  29. @translation = Translation.new(params[:translation])
  30. if @translation.save
  31. render :json => @translation, :status => :created
  32. else
  33. render :json => @translation.errors, :status => :unprocessable_entity
  34. end
  35. end
  36. # PUT /translations/1
  37. def update
  38. @translation = Translation.find(params[:id])
  39. if @translation.update_attributes(params[:translation])
  40. render :json => @translation, :status => :ok
  41. else
  42. render :json => @translation.errors, :status => :unprocessable_entity
  43. end
  44. end
  45. # DELETE /translations/1
  46. def destroy
  47. @translation = Translation.find(params[:id])
  48. @translation.destroy
  49. head :ok
  50. end
  51. end