Rails 中的分页哈希
我正在使用 will_paginate gem 对我的 Rails 应用程序进行分页。我正在用我的一个集合构建一个树视图结构(基本上是一个哈希结构)。它是这样的:
Root
╰─╴Suite
╰─╴TestCase
╰─╴Ic
我想对此进行分页。我尝试了以下代码,但它抛出一个错误,指出 undefined method 'paginate' for #
。
控制器代码:
def index
@ics = Ic.search(
params[ :root_name ], params[ :suite_name ],
params[ :case_name ], params[ :name ],
'f'
)
@ics_temp = Ic.make_tree( @ics ).paginate :per_page => 100,
:page => params[ :all_ics ]
end
查看代码:
- form_tag "/ics/mass_action", :method => :post, :multipart => true do
<div id="update_ics_table">
= render "listing",
:show_check_boxes => show_check_boxes,
:root_name => params[:root_name],
:suite_name => params[:suite_name],
:case_name => params[:case_name],
:name => params[:name],
:ic_filter => 1
</div>
= will_paginate @ics_temp, :param_name => :all_ics
另外请帮助我如何使用ajaxify。
I am using the will_paginate gem to paginate my rails application. I am building a tree view structure (basically a hash structure) with one of my collections. It goes like this:
Root
╰─╴Suite
╰─╴TestCase
╰─╴Ic
I want to paginate this. I tried the following code but it throws an error saying undefined method 'paginate' for #<Hash:0xb707f190>
.
Controller code:
def index
@ics = Ic.search(
params[ :root_name ], params[ :suite_name ],
params[ :case_name ], params[ :name ],
'f'
)
@ics_temp = Ic.make_tree( @ics ).paginate :per_page => 100,
:page => params[ :all_ics ]
end
View code:
- form_tag "/ics/mass_action", :method => :post, :multipart => true do
<div id="update_ics_table">
= render "listing",
:show_check_boxes => show_check_boxes,
:root_name => params[:root_name],
:suite_name => params[:suite_name],
:case_name => params[:case_name],
:name => params[:name],
:ic_filter => 1
</div>
= will_paginate @ics_temp, :param_name => :all_ics
Also please help me with how to ajaxify this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要对
Hash
进行分页,您必须向Hash
类添加paginate
方法。这是一个链接,向您展示如何使用数组执行此操作。
按照它说的做,但是根据哈希更改函数。
To paginate a
Hash
, you'll have to addpaginate
method to ClassHash
.Here is a link, that shows you how to do so with an Array.
Just do as it says, but change the function as per Hash.