bootstrap 与 rails 2.3.8整合之:will_paginate插件的使用

3 篇文章 0 订阅
2 篇文章 0 订阅
新增render, application_helper.erb
class BootstrapLinkRenderer < ::WillPaginate::LinkRenderer
  def initialize
    #@gap_marker = @template.content_tag :li, @template.content_tag(:link(super, '#')), :class => 'disabled'
    @gap_marker = '<li class="disabled"><a href="javascript:void(0)">…</a></span>'
  end

   def to_html
     links = @options[:page_links] ? windowed_links : []
     links.unshift page_link_or_span(@collection.previous_page, 'disabled prev_page', @options[:previous_label])
     links.push    page_link_or_span(@collection.next_page,     'disabled next_page', @options[:next_label])

     html = links.join(@options[:separator])
     html = html.html_safe if html.respond_to? :html_safe
     @options[:container] ? @template.content_tag(:ul, html, html_attributes) : html
   end

   def page_link(page, text, attributes = {})
     @template.content_tag(:li, @template.link_to(text, url_for(page)), attributes)
   end

   def page_span(page, text, attributes = {})
     @template.content_tag(:li,@template.link_to(text,"javascript:void(0)"), attributes)
   end
end

view层如下引用
 <%=will_paginate @videos, {:renderer => BootstrapLinkRenderer,:previous_label => "上一页", :next_label => "下一页"} %>

还必须增加如下css才完美
<style type="text/css">
  .pagination .current a, .pagination .current a:hover{
    background-color: transparent;
    color: #999999;
    cursor: default;
  } 
</style>

rails 3.0 以上,请参考:

http://www.leonardteo.com/2011/12/rails-bootstrap-and-will_paginate/


will_paginate.zh.yml will pageinate 的中文化

zh:
  will_paginate:
    models:
      entry:  资源
    previous_label: "← 前一页"
    next_label: "下一页 →"
    page_gap: "... ..."

    page_entries_info:
      single_page:
        zero:  "没有发现 %{model} "
        one:   "显示 1 %{model}"
        other: "显示所有 %{count} %{model}"
      single_page_html:
        zero:  "没有发现 %{model} "
        one:   "显示 <b>1</b> %{model}"
        other: "显示 <b>所有 %{count}</b> %{model}"

      multi_page: "显示 %{model} %{from} - %{to} 共 %{count} 所有记录"
      multi_page_html: "显示 %{model} <b>%{from} - %{to}</b> 共 <b>%{count}</b> 所有记录"




没有发现 entries 的问题解决

总算比较圆满的结局了该问题,增加了 models: entry 资源

      defaults = ["models.#{model_key}"]
      defaults << Proc.new { |_, opts|
        if model.respond_to? :model_name
          model.model_name.human(:count => opts[:count])
        else
          name = model_key.to_s.tr('_', ' ')
          raise "can't pluralize model name: #{model.inspect}" unless name.respond_to? :pluralize
          opts[:count] == 1 ? name : name.pluralize
        end
      }
      model_name = will_paginate_translate defaults, :count => model_count
will_paginate_translate 的方法定义如下
  def will_paginate_translate(keys, options = {})
      if defined? ::I18n
        defaults = Array(keys).dup
        defaults << Proc.new if block_given?
        ::I18n.translate(defaults.shift, options.merge(:default => defaults, :scope => :will_paginate))
      else
        key = Array === keys ? keys.first : keys
        yield key, options
      end
    end



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值