gpt4 book ai didi

ruby-on-rails - 事件管理员 CSV 导出自定义查询范围

转载 作者:数据小太阳 更新时间:2023-10-29 06:48:27 26 4
gpt4 key购买 nike

我正在使用活跃的管理员导出 CSV 选项。它返回与特定表相关的所有值。

我只想要特定月份的报告。

有人能帮忙吗?

最佳答案

您可以编写自己的 csv 导出器

collection_action :download_report, :method => :get do
users = User.where('created_at >= ?', Date.today - 1.month)
csv = CSV.generate( encoding: 'Windows-1251' ) do |csv|
# add headers
csv < [ #Some header ]
# add data
users.each do |user|
csv << [ user.created_at ]
end
end
# send file to user
send_data csv.encode('Windows-1251'), type: 'text/csv; charset=windows-1251; header=present', disposition: "attachment; filename=report.csv"
end

action_item only: :index do
link_to('csv report'), params.merge(:action => :download_report))
end

index :download_links => false do
# off standard download link
end

这只是您的示例。你的代码可以是另一个

关于ruby-on-rails - 事件管理员 CSV 导出自定义查询范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20946431/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com