Last Updated: February 25, 2016
·
2.911K
· sadfuzzy

Custom page in ActiveAdmin

It is a cheatsheet. I created it to bookmark working solution, because it's kind of rare encountered.

ActiveAdmin.register_page 'CustomPage' do
  menu parent: "Main"

  content do
    count = SomeModel.count
    render partial: 'admin/custompage/upload_form', locals: {count: count}
  end

  page_action :import, method: :post do
    imported = Import.new(params[:file].path)
    imported.import
    redirect_to admin_custompage_path, notice: "Imported #{imported.element_count}."
  end
end
h2 Import XML
h3
  ' Total:
  b= count

= form_tag(admin_custompage_import_path, multipart: true) do
  = file_field_tag 'file', required: 'required'
  = submit_tag 'Upload', name: nil