will_paginate 与 rails3集成时,分页 界面显示不出来

rails 3新增XXS机制,导致html标签在output的时候要进行校验,使用will_paginate的时候会有一些问题,显示不出分页界面,如:
<span class="disabled">&lt;&lt;上一页</span> <span class="current">1</span> <a href="/store/index?page=2">2</a> <a href="/store/index?page=3">3</a> <a href="/store/index?page=2">下一页&gt;&gt;</a>

这里面是由于will_paginate中没有对rails 3的新特性予以支持,
需要修改内容 will_paginate\view_helpers.rb中的to_html方法

    def to_html
      links = @options[:page_links] ? windowed_paginator : []
      # previous/next buttons
      links.unshift page_link_or_span(@collection.previous_page, 'disabled', @options[:prev_label])
      links.push    page_link_or_span(@collection.next_page,     'disabled', @options[:next_label])

      html = links.join(@options[:separator])
      html = "每页显示<b>#{@collection.per_page}</b>条数据,共有<b>#{total_pages}</b>页,  共有<b>#{@collection.total_entries}</b>条数据" + html  
     html = html.html_safe if html.respond_to? :html_safe
     @options[:container] ? @template.content_tag(:div, html, html_attributes) : html
    end


原理就是在rails在进行html_safe校验之前,进行安全赋值。

你可能感兴趣的:(html,Ruby,Rails)