Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 

80 righe
2.0 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. @document.name = @document.doc_file_name
  24. if Document.exists?(doc_fingerprint: @document.doc_fingerprint)
  25. end
  26. respond_to do |format|
  27. if @document.save
  28. format.html { redirect_to @document, notice: 'Document was successfully created.' }
  29. format.json { render :show, status: :created, location: @document }
  30. else
  31. format.html { render :new }
  32. format.json { render json: @document.errors, status: :unprocessable_entity }
  33. end
  34. end
  35. end
  36. # PATCH/PUT /documents/1
  37. # PATCH/PUT /documents/1.json
  38. def update
  39. respond_to do |format|
  40. if @document.update(document_params)
  41. format.html { redirect_to @document, notice: 'Document was successfully updated.' }
  42. format.json { render :show, status: :ok, location: @document }
  43. else
  44. format.html { render :edit }
  45. format.json { render json: @document.errors, status: :unprocessable_entity }
  46. end
  47. end
  48. end
  49. # DELETE /documents/1
  50. # DELETE /documents/1.json
  51. def destroy
  52. @document.destroy
  53. respond_to do |format|
  54. format.html { redirect_to documents_url, notice: 'Document was successfully destroyed.' }
  55. format.json { head :no_content }
  56. end
  57. end
  58. private
  59. # Use callbacks to share common setup or constraints between actions.
  60. def set_document
  61. @document = Document.find(params[:id])
  62. end
  63. # Never trust parameters from the scary internet, only allow the white list through.
  64. def document_params
  65. params.require(:document).permit(:doc)
  66. end
  67. end