-
Switching to Gemcutter
Posted 10 October 2009So GitHub dropped gem support. No problem – Gemcutter, the drop-in replacement, is simple to use. (And now my gems get canonical names!) I’ve pushed my Rails gems (ActiveUrl, Subdomain Routes and Paged Scopes) to the new host, and updated the README installation instructions.
Installing the gems on a server now goes as follows (no mholling namespace):
-
Testing with Subdomain Routes
Posted 25 August 2009A lot of the queries I’ve had about the SubdomainRoutes gem relate to testing. There are two different areas where this comes into play – controller testing and testing of the routes themselves.
I’ll use a simple routes.rb as an example for this article:
-
Paged Scopes, Part III: Paginating Your Views
Posted 02 July 2009In my two previous articles, I’ve been describing my new Paged Scopes pagination gem for ActiveRecord and Rails. In this final installment I’ll describe how to use the library to render pagination links in your views.
Pagination Links
The basic idea is to render a row of numbered links for a few pages either side of the one being viewed. This is referred to as the inner window. An outer window is often also included – this shows links for the first and last few pages at the start and end of the list. Usually, next page and previous page links are also sandwiched around the numbered links.
The will_paginate rdoc has some good links to articles on pagination UI design:
-
Paged Scopes, Part II: Routing and Controller Methods
Posted 30 June 2009Last week I described the basics of my Paged Scopes rubygem for ActiveRecord. In this article I’ll describe some routing and controller methods that make Paged Scope pagination very easy to use in your Rails controllers.
(It should be noted that the use of these methods is optional. If you don’t like them, you don’t have to use them! Design your routes and paginate your collections in your controllers however you see fit.)
Page Routing
The most common way to represent a paginated collection in an URL is to tack on the page number as a query parameter: http://www.example.com/articles?page=3, for example.
-
Paged Scopes: A Will_paginate Alternative
Posted 28 June 2009The first time I needed to paginate data in a Rails site, I went straight for the de-facto standard, which, since Rails 2.0, has undoubtedly been will_paginate. However, it didn’t take me long to discover it couldn’t do all that I wanted it to.
Most importantly, I wanted to be able to redirect from a resource member action (the update action, say) back to the index action, with the page set so that the edited resource would be part of the paged list. I couldn’t see a way to do that with will_paginate. I found the will_paginate helper a bit messy – ever heard of block helpers? And finally, I wanted my pages to be objects, not just numbers. This would let me load them in controllers and pass them to named routes and have them just work. Will_paginate didn’t seem to fit the bill.
Now don’t get me wrong; will_paginate must be pretty awesome – it’s the third most watched repo on GitHub as I write this. But choice is always good, and to me, will_paginate seems a bit bloated and ill-fitting to the way I like to structure my code.
So, naturally, I rolled my own pagination solution. I’ve finally packaged it up and released it as a new ActiveRecord pagination gem, Paged Scopes. It’s everything I need in Rails pagination and nothing I don’t. It’s also lightweight and pretty solid. Check it out!