ruby-on-rails – Twitter引导程序与will_paginate一起使用

我让will_paginate工作正常,但我正面临错误连接Twitter Bootstrap.我的单行will_paginate链接成为项目符号列表.

<% will_paginate @thing %>

变为:

<%= will_paginate @thing, :renderer => BootstrapPagination::Rails %>

或者我觉得更现代:

<%= will_paginate @thing, renderer: BootstrapPagination::Rails %>

我得到了垂直项目符号列表,我试过包括=和 – 符号,但我迷路了.

最佳答案
要使用will_paginate和bootstrap,建议将gem“bootstrap-will_paginate”添加到项目中(参见http://www.railstutorial.org/book/updating_and_deleting_users#sec-pagination).

此外,如果您使用的是Twitter Bootstrap 3.x,则会有一个过多的div包装分页列表以进行删除.
感谢这个补丁:https://gist.github.com/henrik/1214011

要总结补丁,请将以下内容放在/ config / initializers中作为will_paginate.rb.

# File config/initializers/will_paginate.rb
# From https://gist.github.com/1214011

module WillPaginate
    module ActionView
        def will_paginate(collection = nil, options = {})
            options[:renderer] ||= BootstrapLinkRenderer
            super.try :html_safe
        end

    class BootstrapLinkRenderer < LinkRenderer
        protected

        def html_container(html)
            tag :ul, html, container_attributes
        end

        def page_number(page)
            tag :li, link(page, page, :rel => rel_value(page)), :class => ('active' if page == current_page)
        end

        def previous_or_next_page(page, text, classname)
            tag :li, link(text, page || '#'), :class => [classname[0..3], classname, ('disabled' unless page)].join(' ')
        end

        def gap
            tag :li, link(super, '#'), :class => 'disabled'
        end

        end
    end
end

转载注明原文:ruby-on-rails – Twitter引导程序与will_paginate一起使用 - 代码日志