No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 

75 líneas
1.9 KiB

  1. class DocumentsController < ApplicationController
  2. before_action :set_document, only: [:show, :edit, :update, :destroy]
  3. # GET /documents
  4. # GET /documents.json
  5. def index
  6. @documents = Document.all
  7. end
  8. # GET /documents/1
  9. # GET /documents/1.json
  10. def show
  11. end
  12. # GET /documents/new
  13. def new
  14. @document = Document.new
  15. end
  16. # GET /documents/1/edit
  17. def edit
  18. end
  19. # POST /documents
  20. # POST /documents.json
  21. def create
  22. @document = Document.new(document_params)
  23. respond_to do |format|
  24. if @document.save
  25. format.html { redirect_to @document, notice: 'Document was successfully created.' }
  26. format.json { render :show, status: :created, location: @document }
  27. else
  28. format.html { render :new }
  29. format.json { render json: @document.errors, status: :unprocessable_entity }
  30. end
  31. end
  32. end
  33. # PATCH/PUT /documents/1
  34. # PATCH/PUT /documents/1.json
  35. def update
  36. respond_to do |format|
  37. if @document.update(document_params)
  38. format.html { redirect_to @document, notice: 'Document was successfully updated.' }
  39. format.json { render :show, status: :ok, location: @document }
  40. else
  41. format.html { render :edit }
  42. format.json { render json: @document.errors, status: :unprocessable_entity }
  43. end
  44. end
  45. end
  46. # DELETE /documents/1
  47. # DELETE /documents/1.json
  48. def destroy
  49. @document.destroy
  50. respond_to do |format|
  51. format.html { redirect_to documents_url, notice: 'Document was successfully destroyed.' }
  52. format.json { head :no_content }
  53. end
  54. end
  55. private
  56. # Use callbacks to share common setup or constraints between actions.
  57. def set_document
  58. @document = Document.find(params[:id])
  59. end
  60. # Never trust parameters from the scary internet, only allow the white list through.
  61. def document_params
  62. params.require(:document).permit(:name, :doc)
  63. end
  64. end