在我看来,我正在渲染部分。这实际上是一个行元素,在表格中出现了大约 500 - 600 次。我急切地加载了所有关联。
但是,问题是,有时相同的部分需要突然不同的渲染时间。
我的 Rails 服务器 o/p:
Rendered admin/invoices/_update.html.erb (1330.3ms)
Rendered admin/invoices/_update.html.erb (4.8ms)
Rendered admin/invoices/_update.html.erb (4.8ms)
Rendered admin/invoices/_update.html.erb (8.8ms)
Rendered admin/invoices/_update.html.erb (4.4ms)
Rendered admin/invoices/_update.html.erb (1309.9ms)
Rendered admin/invoices/_update.html.erb (4.7ms)
Rendered admin/invoices/_update.html.erb (4.6ms)
Rendered admin/invoices/_update.html.erb (4.6ms)
Rendered admin/invoices/_update.html.erb (1322.6ms)
Rendered admin/invoices/_update.html.erb (4.2ms)
此外,没有特定的行每次都需要更长的时间。
在我的 View 文件中:
<% @updates.each do |update| %>
<%= render :partial => 'update', :locals => {:user => update[0]} #each of this is a row %>
<% end %>
更新:
还建议这是否是这样做的好方法?即:多次循环部分。我不能使用分页和 Ajax 来固定东西。!还有其他方法吗。?
最佳答案
Partials 在渲染集合时非常有用。当您通过 :collection 选项将集合传递给局部时,将为集合中的每个成员插入一次局部:
<%= render :partial => 'update', :collection => @updates %>
这也有一个简写。假设@updates 是更新实例的集合,您可以简单地将其写入 index.html.erb 以产生相同的结果:
<%= render @updates %>
Section 3.4.5 of the Rails Guides详细解释了这一点。
关于ruby-on-rails-3 - Rails 部分有时需要太多时间来渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14284315/