R
R
Roman Mirilaczvili2018-12-06 15:28:20
Ruby on Rails
Roman Mirilaczvili, 2018-12-06 15:28:20

How to generate CSV from cached data in ActiveAdmin?

There is a basic admin interface built with ActiveAdmin.
There is a list of some data (:name, :completed_at) whose values ​​are in the Rails.cache for some key 'foo'.
You need to return a CSV file with a list from this array to the user in ActiveAdmin.
Added the following file
app/admin/status_reports.rb

ActiveAdmin.register StatusReport do

  csv do
    column :name
    column :completed_at
  end

end

What if the StatusReport is not projected to the database, but should take data from the cache?
How to define the StatusReport class? After all, it cannot be inherited from ActiveRecord::Base, right?
Tried like this:
app/models/status_report.rb
class StatusReport < ApplicationRecord

  attr_accessor :name, :completed_at

  def initialize   
  end

end
but naturally swears by an error
PG::UndefinedTable: ERROR: relation "status_reports" does not exist
.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question