Add document upload from admin section

This commit is contained in:
voodoorai2000
2018-11-29 12:30:47 +01:00
committed by decabeza
parent 9df433eeda
commit 19b7526421
13 changed files with 247 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
class Admin::SiteCustomization::DocumentsController < Admin::SiteCustomization::BaseController
def index
@documents = Document.admin.page(params[:page])
end
def new
@document = Document.new
end
def create
@document = initialize_document
if @document.save
notice = t("admin.documents.create.success_notice")
redirect_to admin_site_customization_documents_path, notice: notice
else
notice = t("admin.documents.create.unable_notice")
redirect_to new_admin_site_customization_document_path, notice: notice
end
end
def destroy
@document = Document.find(params[:id])
@document.destroy
notice = t("admin.documents.destroy.success_notice")
redirect_to admin_site_customization_documents_path, notice: notice
end
private
def initialize_document
document = Document.new
document.attachment = params.dig(:document, :attachment)
document.title = document.attachment_file_name
document.user = current_user
document.admin = true
document
end
end