新增render, application_helper.erb
view层如下引用
还必须增加如下css才完美
没有发现 entries 的问题解决
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