Module: ChatManager::CsvDownloadable

Extended by:
ActiveSupport::Concern
Defined in:
lib/chat_manager/csv_downloadable.rb

Constant Summary collapse

CSV_HEADERS =
[ "Chat Title", "Role", "Message Content", "Sent At", "Model" ].freeze

Instance Method Summary collapse

Instance Method Details

#download_all_csvObject



20
21
22
23
24
25
26
# File 'lib/chat_manager/csv_downloadable.rb', line 20

def download_all_csv
  chats = current_user.chats.includes(messages: :prompt_manager_prompt_execution)

  csv_data = generate_csv_for_chats(chats)

  send_data csv_data, filename: "all_chats_#{Date.today}.csv", type: "text/csv"
end

#download_csvObject



11
12
13
14
15
16
17
18
# File 'lib/chat_manager/csv_downloadable.rb', line 11

def download_csv
  chat = current_user.chats.includes(messages: :prompt_manager_prompt_execution).find_by!(uuid: params[:id])

  csv_data = generate_csv_for_chats([ chat ])

  filename = "chat_#{chat.title.to_s.parameterize.presence || chat.uuid}_#{Date.today}.csv"
  send_data csv_data, filename: filename, type: "text/csv"
end