gpt4 book ai didi

ruby-on-rails - 无法导出 rails 中超过 5000 行

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

我做了一个应用程序将我的所有政策导出到 excel 文件中,但没有导出我的所有信息

这是mysql中的查询

select * from policies where deleted = 0 AND (state = 0 OR state= 1) ORDER BY state ASC 
i got 11,408 total when i executed it on mysql

这是我的 Controller

  @search = Policy.find_by_sql("select * from policies where deleted = 0 AND (state = 0 OR state= 1) ORDER BY state ASC ")
@policies = @search.paginate(:page => params[:page], :per_page => 10)
@results = @search

respond_to do |format|
format.html
format.xls { send_data render_to_string(:partial=>"report"), :filename => "Report.xls" }
end

这是我的看法

 <%= link_to "Export Excel",{:controller=>"policy",:action=>"report", :format=>"xls",:page => params[:page] }  %>

这是我的部分观点

<% @results.each do |policy| %>
<%= policy.num_policy %>
<% end %>

实际上只导出 5078 行,我应该有 11,408 行

有人可以帮我解决这个问题吗?

非常感谢帮助

这是我的最后一篇日志

 Rendered policy_management/policy/_report_by_ejecutive (42929.2ms)
Sending data Report_2013-11-11.xls
Completed in 43533ms (View: 0, DB: 0) | 200 OK [http://0.0.0.0/policy_management/policy/generate_print_ejecutive?format=xls]

最佳答案

你应该使用批量查询 ActiveRecord Batch query

@search = Policy.find_by_sql("select * from policies where deleted = 0 AND (state = 0 OR state= 1) ORDER BY state ASC ")

@search = Policy.where("deleted = 0 AND (state = 0 OR state = 1)").order("state ASC")

在你的部分

<% @results.find_each(:batch_size => 1000) do |policy| %>
<%= policy.num_policy %>
<% end %>

关于ruby-on-rails - 无法导出 rails 中超过 5000 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19775306/

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