Semantics, Code and Circumstance
April 10, 2010: This afternoon I recieved a visit from a plushy black cat. I've never seen her before and since she has a collar she may be moved in with her owner in the last days.
Read more about project 365 ...It is wildly known and even somewhat accepted, that the pagination mechanism of Mephisto 0.8.2 is very buggy and non-functional. However, paging blog posts is a feature that kills a blog engine if it does not work. Fortunately, James of Rails Talk wrote a nice tutorial for bringing up paging again. His description is easy done and works well, as long as you have only one section, the mandatory Home section.
However, blogs with multiple sections (like this one) faced a strange problem with doubled section names in URLs. A workaround with separate URL helpers for each section exists, but is utterly unhandy. After some investigation it turns out, that a small change to the original tutorial solves the whole section difficulty. The original instruction was to add the following to mephisto_paged_article_list/lib/paged_article_list/link_helpers.rb:
def path_for( path_info, page_number )
return path_info[:path] + "/page/" + page_number.to_s
end
Now, when using this with multiple sections, path_info[:path] contains the name of the current section (or nothing, if the section is Home). Moreover, the produced path is a relative path, so that the returned string will be appended to the base URL that already contains the section name as the last part. This is where the doubled section names come from. To remove this behaviour, we need to change the code a little bit:
def path_for( path_info, page_number )
path = path_info[:path] + '/page/' + page_number.to_s
path_info[:path].blank? ? path : '/' + path
end
With this code, we assemble the path the same way, but precede it with a ’/’ whenever the section name is not empty. This gives us a non-relative URL without the doubled section name and thus correct pagination URLs for all sections.