Sar*_*mAr 9 ruby ruby-on-rails activeadmin
我使用的是主动管理导出CSV选项.它返回与特定表相关的所有值.
我希望报告仅针对特定月份.
有人可以帮忙吗?
Зел*_*ный 17
你可以编写自己的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
Run Code Online (Sandbox Code Playgroud)
这只是你的榜样.你的代码可以是另一个
| 归档时间: |
|
| 查看次数: |
5982 次 |
| 最近记录: |