Skip to content

Instantly share code, notes, and snippets.

@jpotts18
Last active August 29, 2015 14:14
Show Gist options
  • Save jpotts18/27fbc3674811db987efa to your computer and use it in GitHub Desktop.
Save jpotts18/27fbc3674811db987efa to your computer and use it in GitHub Desktop.
class DocumentsController < ApplicationController
before_action :set_document, only: [:show, :edit, :update, :destroy]
before_filter :load_folder
# GET /documents
# GET /documents.json
def index
@documents = documents.all
end
private
def load_folder
@folder = Folder.find(params[:folder_id])
end
def documents
@folder ? @folder.documents : Document
end
# Use callbacks to share common setup or constraints between actions.
def set_document
@document = Document.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def document_params
params.require(:document).permit(:name, :text, :url, :user_id, :folder_id, :label_id)
end
end
@elorest
Copy link

elorest commented Jan 28, 2015

Looks fine except that folder isn't defined as far as I can tell.
assuming. There's a @folder.

@elorest
Copy link

elorest commented Jan 28, 2015

@folder ? @folder.documents : Document.all

@elorest
Copy link

elorest commented Jan 28, 2015

That's probably better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment