Skip to content

Commit 5238d8a

Browse files
committed
[Fixes browsermedia#724] Allow pagination to work with any model
1 parent 03aff3f commit 5238d8a

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

app/helpers/cms/application_helper.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -171,18 +171,17 @@ def render_pagination(collection, content_type, options={})
171171
if collection.blank?
172172
content_tag(:div, "No Content", :class => "pagination")
173173
else
174-
model_class = content_type.instance_of?(Class) ? content_type : content_type.model_class
175174
render :partial => "pagination", :locals => {
176175
:collection => collection,
177-
:first_page_path => polymorphic_path(engine_aware_path(model_class), {:page => 1}.merge(options)),
178-
:previous_page_path => polymorphic_path(engine_aware_path(model_class), {:page => collection.previous_page ? collection.previous_page : 1}.merge(options)),
179-
:current_page_path => polymorphic_path(engine_aware_path(model_class), options),
180-
:next_page_path => polymorphic_path(engine_aware_path(model_class), {:page => collection.next_page ? collection.next_page : collection.current_page}.merge(options)),
181-
:last_page_path => polymorphic_path(engine_aware_path(model_class), {:page => collection.total_pages}.merge(options))
176+
:first_page_path => url_for({:page => 1}.merge(options)),
177+
:previous_page_path => url_for({:page => collection.previous_page ? collection.previous_page : 1}.merge(options)),
178+
:current_page_path => url_for(options),
179+
:next_page_path => url_for({:page => collection.next_page ? collection.next_page : collection.current_page}.merge(options)),
180+
:last_page_path => url_for({:page => collection.total_pages}.merge(options))
182181
}
183182
end
184183
end
185-
184+
186185
def url_with_mode(url, mode)
187186
url = "" unless url # Handles cases where request.referrer is nil (see cms/_page_toolbar.html.erb for an example)
188187
uri = URI.parse(url)

app/views/cms/application/_pagination.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<%= link_to "<< &nbsp;".html_safe, first_page_path, :id => "first_page_link" %>
1111
<%= link_to "< &nbsp;".html_safe, previous_page_path, :id => "previous_page_link" %>
1212
<% url = URI.parse(current_page_path) %>
13-
<%= form_tag url.path, :method => :get, :class => "current_page", style: 'display:inline' do %>
13+
<%= form_tag url_for({}), :method => :get, :class => "current_page", style: 'display:inline' do %>
1414
<% url.query.to_s.split('&').each do |p|
1515
; k, v = p.split('=') %>
1616
<%= hidden_field_tag(k, CGI::unescape(v.to_s), :id => "pagination_hidden_#{k}") unless k == "page" %>

0 commit comments

Comments
 (0)