require 'jbuilder' class ContentFoldersController < ApplicationController respond_to :json rescue_from 'Mongoid::Errors::DocumentNotFound' do |exception| render json: {errors: [exception.message]}, status: 404 end # GET http://localhost:3000/content_folders # GET http://localhost:3000/content_folders.json def index @content_folder = ContentFolder.last.child_folders unless ContentFolder.last.nil? if @content_folder.nil? render json: {}, status: :not_found else respond_with @content_folder end end #GET http://localhost:3000/content_folders/529_lit_center #GET http://localhost:3000/content_folders/529_lit_center/private_college_529?nested=false def show path = params[:id] nested = params[:nested] @content_folder = ContentFolder.find_folder_by_relative_path(path) unless path.nil? @nested_view = true if (nested=="false") @nested_view = false end if @content_folder.nil? render json: {}, status: :not_found else respond_with @content_folder end end # POST /content_folder # POST /content_folder.json def create content_folder = ContentFolder.new(params[:content_folder]) old_content_folder = ContentFolder.last if content_folder.save old_content_folder.delete unless old_content_folder.nil? render json: content_folder, status: :created else render json: content_folder.errors, status: :unprocessable_entity end end end