Files
grecia/app/controllers/admin/site_customization/documents_controller.rb
2019-04-30 11:59:08 +02:00

41 lines
1.0 KiB
Ruby

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