Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Add support for page parameter in custom routes like "/foo/page/2"

  • Loading branch information...
commit 4d2da56949b66f838d932724ca40bf7f93627b1f 1 parent fb38b83
Mislav Marohnić mislav authored
6 CHANGELOG
... ... @@ -1,3 +1,9 @@
  1 +== 2.2.2, released 2008-04-21
  2 +
  3 +* Add support for page parameter in custom routes like "/foo/page/2"
  4 +* Change output of "page_entries_info" on single-page collection and erraneous
  5 + output with empty collection as reported by Tim Chater
  6 +
1 7 == 2.2.1, released 2008-04-08
2 8
3 9 * take less risky path when monkeypatching named_scope; fix that it no longer
2  README.rdoc
Source Rendered
@@ -114,7 +114,7 @@ contributions or just simply awesome ideas:
114 114 Chris Wanstrath, Dr. Nic Williams, K. Adam Christensen, Mike Garey, Bence
115 115 Golda, Matt Aimonetti, Charles Brian Quinn, Desi McAdam, James Coglan, Matijs
116 116 van Zuijlen, Maria, Brendan Ribera, Todd Willey, Bryan Helmkamp, Jan Berkel,
117   -Lourens Naudé, Rick Olson.
  117 +Lourens Naudé, Rick Olson, Russell Norris.
118 118
119 119
120 120 == Usable pagination in the UI
2  lib/will_paginate/view_helpers.rb
@@ -280,7 +280,7 @@ def url_for(page)
280 280 end
281 281
282 282 url = @template.url_for(@url_params)
283   - @url_string = url.sub(/([?&]#{CGI.escape param_name}=)#{page}/, '\1@')
  283 + @url_string = url.sub(%r!([?&/]#{CGI.escape param_name}[=/])#{page}!, '\1@')
284 284 return url
285 285 end
286 286 @url_string.sub '@', page.to_s
8 test/lib/view_test_process.rb
@@ -5,15 +5,19 @@
5 5 WillPaginate.enable_actionpack
6 6
7 7 ActionController::Routing::Routes.draw do |map|
  8 + map.connect 'dummy/page/:page', :controller => 'dummy'
8 9 map.connect ':controller/:action/:id'
9 10 end
10 11
11 12 ActionController::Base.perform_caching = false
12 13
13 14 class DummyRequest
  15 + attr_accessor :symbolized_path_parameters
  16 +
14 17 def initialize
15 18 @get = true
16 19 @params = {}
  20 + @symbolized_path_parameters = { :controller => 'foo', :action => 'bar' }
17 21 end
18 22
19 23 def get?
@@ -24,10 +28,6 @@ def post
24 28 @get = false
25 29 end
26 30
27   - def symbolized_path_parameters
28   - { :controller => 'foo', :action => 'bar' }
29   - end
30   -
31 31 def relative_url_root
32 32 ''
33 33 end
19 test/view_test.rb
@@ -220,6 +220,15 @@ def test_complex_custom_page_param
220 220 end
221 221 end
222 222
  223 + def test_custom_routing_page_param
  224 + @request.symbolized_path_parameters.update :controller => 'dummy', :action => nil
  225 + paginate :per_page => 2 do
  226 + assert_select 'a[href]', 6 do |links|
  227 + assert_links_match %r{/page/(\d+)$}, links, [2, 3, 4, 5, 6, 2]
  228 + end
  229 + end
  230 + end
  231 +
223 232 ## internal hardcore stuff ##
224 233
225 234 class LegacyCollection < WillPaginate::Collection
@@ -307,14 +316,22 @@ def validate_page_numbers expected, links, param_name = :page
307 316 })
308 317 end
309 318
310   - def assert_links_match pattern, links = nil
  319 + def assert_links_match pattern, links = nil, numbers = nil
311 320 links ||= assert_select 'div.pagination a[href]' do |elements|
312 321 elements
313 322 end
  323 +
  324 + pages = [] if numbers
314 325
315 326 links.each do |el|
316 327 assert_match pattern, el['href']
  328 + if numbers
  329 + el['href'] =~ pattern
  330 + pages << $1.to_i
  331 + end
317 332 end
  333 +
  334 + assert_equal pages, numbers, "page numbers don't match" if numbers
318 335 end
319 336
320 337 def assert_no_links_match pattern

0 comments on commit 4d2da56

Please sign in to comment.
Something went wrong with that request. Please try again.