本文介绍了自定义kaminari分页模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自定义默认的 kaminari 模板时遇到了困难.

I'm having difficulty customizing the default kaminari template.

我已经使用生成器创建了 kaminari 模板文件.在 kaminari/paginator.html.haml:

I've used the generator to create kaminari template files. In kaminari/paginator.html.haml:

= paginator.render do
  %nav.pagination

我想要做的就是访问其中的 actionview 助手,例如 link_to 或渲染.我已经搜索了源代码,但找不到传递给此渲染方法的帮助程序的任何倾斜.

All I want to do is access the actionview helpers within this, like link_to, or render. I've searched the source code and I can't find any incline of the helper being passed to this render method.

基本上,能够做到这一点:

Essentially, being able to do this:

= paginator.render do
  %nav.pagination
    = render :partial => 'custom links'
    = link_to "custom link", custom_path

..会解决我的问题.

推荐答案

我没有得到满意的答案,所以我将提交我自己的解决方案.

I didn't get a satisfactory answer, and so I'll submit my own solution.

Helper 不能在 paginator.render 块中使用.

Helpers cannot be used in the paginator.render block.

所以,首先我生成kaminari自定义模板文件:

So, first I generate kaminari custom template files:

rails g kaminari:views default -e haml

创建一个包含内容的新文件 kaminari/custom.html.haml:

Create a new file kaminari/custom.html.haml with the contents:

#pagination
  = paginate custom
  = render :partial => "kaminari/custom_view_file"

将视图文件中的 kaminari 分页助手 (paginate @results) 替换为:

Replace kaminari paginator helper (paginate @results) in your view file with:

= render :partial => "kaminari/custom", :object => @results

这篇关于自定义kaminari分页模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-07 17:38