will_paginate 修改 view


#1

直接寫 code

// config/initialize/pagination_link_renderer.rb

# -*- encoding : utf-8 -*-
require 'will_paginate/view_helpers/link_renderer'
require 'will_paginate/view_helpers/action_view'
class PaginationLinkRenderer < ::WillPaginate::ActionView::LinkRenderer
  protected
  def page_number(page)
    unless page == current_page
      tag(:li, link(page, page, :rel => rel_value(page)))
    else
      tag(:li, link(page, '#', :rel => rel_value(page)), :class => "active disabled")
    end
  end
  def gap
    tag(:li, link('...' , '#') , :class => "disabled")
  end
  def previous_or_next_page(page, text, classname)
    tag(:li, link(text , page || '#'), :class => page ? classname : classname + ' disabled')
  end
  def html_container(html)
    tag(:div , tag(:ul, html , container_attributes) , :class => 'pagination_label col-xs-12 center')
  end
end

//view下使用

<%= raw(will_paginate(@paginate , :inner_window => 4 , :outer_window => 2, :renderer => PaginationLinkRenderer)) if @paginate %>

anyway will_paginate 可以用這種寫法來改它的view,而裡面有提示你對照的class在這邊

https://github.com/mislav/will_paginate/blob/3-0-stable/lib/will_paginate/view_helpers/action_view.rb

其實繼承下來,修改,餵進去,就可以跑出你要的view才是,而這段是針對新手教學影片的 ace template 所寫的就是了 : )