Class: Railspress::Admin::ExportsController

Inherits:
BaseController
  • Object
show all
Defined in:
app/controllers/railspress/admin/exports_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



14
15
16
17
18
19
20
21
22
23
24
# File 'app/controllers/railspress/admin/exports_controller.rb', line 14

def create
  export = Export.create!(
    export_type: export_params[:export_type],
    status: "pending"
  )

  ExportPostsJob.perform_later(export.id)

  redirect_to typed_admin_exports_path(type: export_params[:export_type]),
              notice: "Export started. You'll be able to download the file once processing completes."
end

#downloadObject



26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/railspress/admin/exports_controller.rb', line 26

def download
  if @export.file.attached?
    send_data @export.file.download,
              filename: @export.filename,
              type: "application/zip",
              disposition: "attachment"
  else
    redirect_to typed_admin_exports_path(type: @export.export_type),
                alert: "Export file not available."
  end
end

#showObject



7
8
9
10
11
12
# File 'app/controllers/railspress/admin/exports_controller.rb', line 7

def show
  @export_type = params[:type]
  @back_path = { "posts" => admin_posts_path }[@export_type]
  @recent_exports = Export.by_type(@export_type).recent
  @post_count = Post.count
end