Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. class DocumentsController < ApplicationController
  2. before_action :set_document, only: [:show, :edit, :update, :destroy]
  3. before_filter :load_folder
  4.  
  5. # GET /documents
  6. # GET /documents.json
  7. def index
  8. @documents = documents.all
  9. end
  10.  
  11. # GET /documents/1
  12. # GET /documents/1.json
  13. def show
  14. end
  15.  
  16. # GET /documents/new
  17. def new
  18. @document = Document.new
  19. end
  20.  
  21. # GET /documents/1/edit
  22. def edit
  23. end
  24.  
  25. # POST /documents
  26. # POST /documents.json
  27. def create
  28. @document = Document.new(document_params)
  29.  
  30. respond_to do |format|
  31. if @document.save
  32. format.html { redirect_to @document, notice: 'Document was successfully created.' }
  33. format.json { render :show, status: :created, location: @document }
  34. else
  35. format.html { render :new }
  36. format.json { render json: @document.errors, status: :unprocessable_entity }
  37. end
  38. end
  39. end
  40.  
  41. # PATCH/PUT /documents/1
  42. # PATCH/PUT /documents/1.json
  43. def update
  44. respond_to do |format|
  45. if @document.update(document_params)
  46. format.html { redirect_to @document, notice: 'Document was successfully updated.' }
  47. format.json { render :show, status: :ok, location: @document }
  48. else
  49. format.html { render :edit }
  50. format.json { render json: @document.errors, status: :unprocessable_entity }
  51. end
  52. end
  53. end
  54.  
  55. # DELETE /documents/1
  56. # DELETE /documents/1.json
  57. def destroy
  58. @document.destroy
  59. respond_to do |format|
  60. format.html { redirect_to documents_url, notice: 'Document was successfully destroyed.' }
  61. format.json { head :no_content }
  62. end
  63. end
  64.  
  65. private
  66.  
  67. def load_folder
  68. @folder = Folder.find(params[:folder_id])
  69. end
  70.  
  71. def documents
  72. folder ? folder.documents : Document
  73. end
  74.  
  75. # Use callbacks to share common setup or constraints between actions.
  76. def set_document
  77. @document = Document.find(params[:id])
  78. end
  79.  
  80. # Never trust parameters from the scary internet, only allow the white list through.
  81. def document_params
  82. params.require(:document).permit(:name, :text, :url, :user_id, :folder_id, :label_id)
  83. end
  84. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement