通过哈希进行分页
{#<Farm id: 1, name: "Farm A", harvest: 2, offers: "Buy now, Delivery", about: "We rocks!",
created_at: "2011-04-23 12:33:43", updated_at: "2011-04-25 09:02:15",logo: "images__9_.jpg", latitude: 42.3214, longitude: -71.0722, address: "555 Dudley Street, Boston, MA", votes_count: 2>=>4482.753159399051, #<Farm id: 2, name: "Farm B",harvest: 3,
offers: "Buy Now, Delivery", about: "We rock the farm A!", created_at: "2011-04-23 12:36:29", updated_at: "2011-04-25 09:02:15", logo: "images__7_.jpg", latitude: 42.3442, longitude: -71.0995, address: "1345 Boylston Street,Boston, MA", votes_count: 2 > => 4482.571841402453}
我剪切了示例(也可以在那里查看http://pastie.org/1871728)。我需要这个哈希的分页。使用 kaminari 或 will_paginate 没有区别。 如果这件事我在视图中输出这个哈希之类
- @sort_farms.count.times do
- farm = @sort_farms.shift
%p
= image_tag farm[0].logo.url.to_s
= farm[0].harvest
的......你能帮我吗?
{#<Farm id: 1, name: "Farm A", harvest: 2, offers: "Buy now, Delivery", about: "We rocks!",
created_at: "2011-04-23 12:33:43", updated_at: "2011-04-25 09:02:15",logo: "images__9_.jpg", latitude: 42.3214, longitude: -71.0722, address: "555 Dudley Street, Boston, MA", votes_count: 2>=>4482.753159399051, #<Farm id: 2, name: "Farm B",harvest: 3,
offers: "Buy Now, Delivery", about: "We rock the farm A!", created_at: "2011-04-23 12:36:29", updated_at: "2011-04-25 09:02:15", logo: "images__7_.jpg", latitude: 42.3442, longitude: -71.0995, address: "1345 Boylston Street,Boston, MA", votes_count: 2 > => 4482.571841402453}
I cut the sample (also can be viewed there http://pastie.org/1871728). I need a pagination for this hash. There is no difference what using kaminari or will_paginate.
If this matter im output in the view this hash like
- @sort_farms.count.times do
- farm = @sort_farms.shift
%p
= image_tag farm[0].logo.url.to_s
= farm[0].harvest
and so on... Can you help me, please.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一的。当您拥有许多农场时,您的代码运行速度会非常慢。
第二。如此简单的分页:
所以在控制器中我们得到了一堆农场。 您应该将所有分页工作包装到您的模型中
现在,视图:
就是这样。
将此视图转换为 HAML 或 erb,我很懒:)
First. Your code will work very slow when you'll have many of farms.
Second. So simple pagination:
So in controller we get a bunch of farms. You should wrap all this pagination work into your model
Now, views:
that's it.
Convert this view into HAML or erb, I was lazy :)