When will_paginate renders strange URLs after Rails upgrade to 3.2

To be honest I didn’t expect I will write again here at this blog. But good news I did manage to find some time to write!

Since 2011 I’m not freelancing anymore, but all the time I use Rails in Nettigo. Codebase used there has it’s roots in Rails 1.2 or even earlier release – first migrations have not timestamps at beginning of filename but numbers, this change was introduced at Rails 2.1. In other words there was a few upgrades in live of this application, and there will be some in future ;) Some upgrades were easy but sometimes You can encounter problems which looks strange and after few hours debugging You have still no idea what is going on :)

Right now I’m in upgrade process from Rails 3.1 to 3.2. It went quite smooth (or at least I think so, since I have not deployed to production environment :) it yet) with one exception – will_paginate have started generating wrong URLs. For example on main page instead of just adding page parameter it have changed path to /about?page=2&controller=Public/products. It looked strange since root was defined, links with link_to were generated for it, page was displayed, but when will_paginate called url_for, it returned garbage – redirecting to About page instead of keeping original URL.

To keep long story short (as usual best solution is to leave code, get some sleep and see at problem again with fresh mind), this diff illustrates what was a cause:

Root was served from controller in namespace (module Public), and with change in routing engine (Rails 3.2 introduced new one) capital letter did the difference.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.