<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Wolfmans Howlings: Paginating acts_as_taggable with will_paginate</title>
    <link>http://blog.wolfman.com/articles/2007/07/30/paginating-acts_as_taggable-with-will_paginate</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>A programmers Blog about Ruby, Rails and a few other issues</description>
    <item>
      <title>Paginating acts_as_taggable with will_paginate</title>
      <description>&lt;p&gt;A question I see asked a lot is how do I paginate acts_as_taggable
(on steroids)?&lt;/p&gt;

&lt;p&gt;I haven't seen any answers I liked, so I created my own, which I'm
sure a few people won't like either ;) But it works for me (tm).&lt;/p&gt;

&lt;p&gt;I use &lt;a href="http://errtheblog.com/post/4791"&gt;will_paginate&lt;/a&gt;, but this does
not work with custom finds that plugins define themselves, as is the
case with
&lt;a href="http://agilewebdevelopment.com/plugins/acts_as_taggable_on_steroids"&gt;acts_as_taggable&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you do use a custom find_by_sql you have to hit the database twice, once to find the total number
of items and then the paginated find.&lt;/p&gt;

&lt;p&gt;I have a situation where I generate a 
&lt;a href="http://blog.wolfman.com/articles/2007/06/23/developing-a-social-networking-site-part-3-tag-cloud"&gt;tag cloud&lt;/a&gt;
with every page, and part of that tag cloud has already calculated the
number of tags for each classification I use.&lt;/p&gt;

&lt;p&gt;I combined this with the &lt;a href="http://paginator.rubyforge.org/"&gt;paginator gem&lt;/a&gt; 
to get myself pages without too many hits to the database.&lt;/p&gt;

&lt;p&gt;The first thing I do is pass the total count I get from the tag cloud
to the action that renders the index for all those items matching the
cloud... If you look at the article cited above I make this
modification, this is dumbed down a bit for the sake of simplicity...&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="ident"&gt;tags&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;tag_counts&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:order&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;tags.name&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
  &lt;span class="ident"&gt;tags&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;each&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;t&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt;
    &lt;span class="ident"&gt;link_to&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;h&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;t&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;name&lt;/span&gt;&lt;span class="punct"&gt;),&lt;/span&gt; &lt;span class="ident"&gt;tagged_post_path&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="symbol"&gt;:tag&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ident"&gt;t&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;name&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:cnt&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ident"&gt;t&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;count&lt;/span&gt;&lt;span class="punct"&gt;))&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This passes the count I have already calculated to the action that
will list the paginated results.&lt;/p&gt;

&lt;p&gt;In my controller I do this to get the paginated results using
will_paginate and the Pagination gem...&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;    &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;tagged&lt;/span&gt;
    &lt;span class="punct"&gt;...&lt;/span&gt;
      &lt;span class="comment"&gt;# page if we can&lt;/span&gt;
      &lt;span class="ident"&gt;size&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;params&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:cnt&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt;
      &lt;span class="keyword"&gt;if&lt;/span&gt; &lt;span class="ident"&gt;size&lt;/span&gt;
        &lt;span class="ident"&gt;per_page&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="number"&gt;10&lt;/span&gt;

        &lt;span class="comment"&gt;# use Paginator gem to do the actual paging&lt;/span&gt;
        &lt;span class="ident"&gt;pager&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Paginator&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;size&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;per_page&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;offset&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;per_page&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt;
          &lt;span class="constant"&gt;Post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find_tagged_with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;params&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:tag&lt;/span&gt;&lt;span class="punct"&gt;],&lt;/span&gt; &lt;span class="symbol"&gt;:limit&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ident"&gt;per_page&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:offset&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ident"&gt;offset&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
        &lt;span class="keyword"&gt;end&lt;/span&gt;

        &lt;span class="comment"&gt;# default to page 1 if not specified&lt;/span&gt;
        &lt;span class="ident"&gt;page&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;params&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:page&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt; &lt;span class="punct"&gt;||&lt;/span&gt; &lt;span class="number"&gt;1&lt;/span&gt;

        &lt;span class="comment"&gt;# gets a paged array of posts&lt;/span&gt;
        &lt;span class="attribute"&gt;@posts&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;returning&lt;/span&gt; &lt;span class="constant"&gt;WillPaginate&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Collection&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;page&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;per_page&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;size&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;p&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt;
          &lt;span class="ident"&gt;p&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;replace&lt;/span&gt; &lt;span class="ident"&gt;pager&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;page&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;page&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;items&lt;/span&gt;
        &lt;span class="keyword"&gt;end&lt;/span&gt;
      &lt;span class="keyword"&gt;else&lt;/span&gt;
        &lt;span class="comment"&gt;# fall back if we don't know the size&lt;/span&gt;
        &lt;span class="attribute"&gt;@posts&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="constant"&gt;Post&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find_tagged_with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;params&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:tag&lt;/span&gt;&lt;span class="punct"&gt;])&lt;/span&gt;
      &lt;span class="keyword"&gt;end&lt;/span&gt;

      &lt;span class="ident"&gt;render&lt;/span&gt; &lt;span class="symbol"&gt;:action&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;index&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;    &lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This fits in nicely with the tag cloud I need to calculate, and it
uses will_paginate just like the regular index action does.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;UPDATE&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I refactored this to be more generally useful, I added the following as a
protected method in &lt;code&gt;application.rb&lt;/code&gt;...&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;  &lt;span class="comment"&gt;# paginate a call to find_tagged_with&lt;/span&gt;
  &lt;span class="comment"&gt;# klass is the tagged class&lt;/span&gt;
  &lt;span class="comment"&gt;# tag is the tag to find&lt;/span&gt;
  &lt;span class="comment"&gt;# count is the total number of items with that tag, if nil count_tags is called&lt;/span&gt;
  &lt;span class="comment"&gt;# per_page is numbe rof items per page&lt;/span&gt;
  &lt;span class="comment"&gt;# page is the page we are on&lt;/span&gt;
  &lt;span class="comment"&gt;# order is the order to return the items in&lt;/span&gt;
  &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;tag_paginator&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;klass&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;tag&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;count&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt;&lt;span class="constant"&gt;nil&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;per_page&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt;&lt;span class="number"&gt;10&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;page&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt;&lt;span class="number"&gt;1&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;order&lt;/span&gt;&lt;span class="punct"&gt;='&lt;/span&gt;&lt;span class="string"&gt;updated_at DESC&lt;/span&gt;&lt;span class="punct"&gt;')&lt;/span&gt;
    &lt;span class="ident"&gt;count&lt;/span&gt; &lt;span class="punct"&gt;||=&lt;/span&gt; &lt;span class="ident"&gt;klass&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;count_tags&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;tag&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
    &lt;span class="ident"&gt;pager&lt;/span&gt; &lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Paginator&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;count&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;per_page&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;offset&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;per_page&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt;
      &lt;span class="ident"&gt;klass&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;find_tagged_with&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;tag&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:order&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ident"&gt;order&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:limit&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ident"&gt;per_page&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="symbol"&gt;:offset&lt;/span&gt; &lt;span class="punct"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ident"&gt;offset&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;

    &lt;span class="ident"&gt;page&lt;/span&gt; &lt;span class="punct"&gt;||=&lt;/span&gt; &lt;span class="number"&gt;1&lt;/span&gt;

    &lt;span class="ident"&gt;returning&lt;/span&gt; &lt;span class="constant"&gt;WillPaginate&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Collection&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;new&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;page&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;per_page&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;count&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;p&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt;
      &lt;span class="ident"&gt;p&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;replace&lt;/span&gt; &lt;span class="ident"&gt;pager&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;page&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;page&lt;/span&gt;&lt;span class="punct"&gt;).&lt;/span&gt;&lt;span class="ident"&gt;items&lt;/span&gt;
    &lt;span class="keyword"&gt;end&lt;/span&gt;
  &lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;I call it from one of my other actions like this...&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;@faqs= tag_paginator(Post, 'FAQ', nil, per_page, params[:page], 'updated_at DESC')
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Passing in nil as the third parameter causes the &lt;code&gt;tag_paginator&lt;/code&gt;
method to call &lt;code&gt;Post.count_tags&lt;/code&gt; which is not part of the
&lt;code&gt;acts_as_taggable&lt;/code&gt; methods, I added it to the SingletonMethods module
myself...&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;module &lt;/span&gt;&lt;span class="module"&gt;ActiveRecord&lt;/span&gt;
  &lt;span class="keyword"&gt;module &lt;/span&gt;&lt;span class="module"&gt;Acts&lt;/span&gt; &lt;span class="comment"&gt;#:nodoc:&lt;/span&gt;
    &lt;span class="keyword"&gt;module &lt;/span&gt;&lt;span class="module"&gt;Taggable&lt;/span&gt; &lt;span class="comment"&gt;#:nodoc:&lt;/span&gt;
      &lt;span class="keyword"&gt;module &lt;/span&gt;&lt;span class="module"&gt;SingletonMethods&lt;/span&gt;

      &lt;span class="punct"&gt;...&lt;/span&gt;

        &lt;span class="comment"&gt;# Return the count of tag tags in this class&lt;/span&gt;
       &lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;count_tags&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="ident"&gt;tag&lt;/span&gt;&lt;span class="punct"&gt;)&lt;/span&gt;
         &lt;span class="ident"&gt;count_by_sql&lt;/span&gt;&lt;span class="punct"&gt;(&amp;quot;&lt;/span&gt;&lt;span class="string"&gt;select count(*) FROM tags, taggings WHERE &lt;/span&gt;&lt;span class="punct"&gt;&amp;quot;&lt;/span&gt; &lt;span class="punct"&gt;+&lt;/span&gt; &lt;span class="ident"&gt;sanitize_sql&lt;/span&gt;&lt;span class="punct"&gt;(['&lt;/span&gt;&lt;span class="string"&gt;name = ? AND tags.id = taggings.tag_id AND taggable_type = ?&lt;/span&gt;&lt;span class="punct"&gt;',&lt;/span&gt; &lt;span class="ident"&gt;tag&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;name&lt;/span&gt;&lt;span class="punct"&gt;]))&lt;/span&gt;
       &lt;span class="keyword"&gt;end&lt;/span&gt;

      &lt;span class="punct"&gt;....&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If you don't want to hack &lt;code&gt;acts_as_taggable&lt;/code&gt; then simply leave that
part out and call the &lt;code&gt;count_by_sql&lt;/code&gt; yourself.&lt;/p&gt;

&lt;p&gt;My refactored tagged action from above now looks like this...&lt;/p&gt;

&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;def &lt;/span&gt;&lt;span class="method"&gt;tagged&lt;/span&gt;
  &lt;span class="punct"&gt;...&lt;/span&gt;
  &lt;span class="ident"&gt;tag&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;params&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:tag&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt;
  &lt;span class="ident"&gt;per_page&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="number"&gt;10&lt;/span&gt;
  &lt;span class="ident"&gt;size&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;params&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:cnt&lt;/span&gt;&lt;span class="punct"&gt;]&lt;/span&gt;
  &lt;span class="attribute"&gt;@posts&lt;/span&gt;&lt;span class="punct"&gt;=&lt;/span&gt; &lt;span class="ident"&gt;tag_paginator&lt;/span&gt;&lt;span class="punct"&gt;(&lt;/span&gt;&lt;span class="constant"&gt;Post&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;tag&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;size&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="number"&gt;10&lt;/span&gt;&lt;span class="punct"&gt;,&lt;/span&gt; &lt;span class="ident"&gt;params&lt;/span&gt;&lt;span class="punct"&gt;[&lt;/span&gt;&lt;span class="symbol"&gt;:page&lt;/span&gt;&lt;span class="punct"&gt;])&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href="http://technorati.com/tag/acts_as_taggable+will_paginate" rel="tag"&gt;&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Mon, 30 Jul 2007 15:04:50 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:e7b7bbf9-0707-48d6-a1ed-7603966b049b</guid>
      <author>Jim Morris</author>
      <link>http://blog.wolfman.com/articles/2007/07/30/paginating-acts_as_taggable-with-will_paginate</link>
      <category>Rails</category>
      <category>acts_as_taggable</category>
      <category>will_paginate</category>
      <trackback:ping>http://blog.wolfman.com/articles/trackback/337</trackback:ping>
    </item>
    <item>
      <title>"Paginating acts_as_taggable with will_paginate" by COP</title>
      <description>&lt;p&gt;yes Eric's solution works for me too... one line thats it. I M LOVING RoR!!!&lt;/p&gt;</description>
      <pubDate>Wed, 23 Apr 2008 01:09:37 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:7aa53d43-c1ec-4fb8-8490-dc3a84479ff9</guid>
      <link>http://blog.wolfman.com/articles/2007/07/30/paginating-acts_as_taggable-with-will_paginate#comment-214</link>
    </item>
    <item>
      <title>"Paginating acts_as_taggable with will_paginate" by P jam aka the nerb</title>
      <description>&lt;p&gt;errr, dave = jim, wolfman, whathaveyou.&lt;/p&gt;</description>
      <pubDate>Thu, 27 Mar 2008 04:39:47 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:6dee2089-fb3b-4981-bcbf-9ea45204210e</guid>
      <link>http://blog.wolfman.com/articles/2007/07/30/paginating-acts_as_taggable-with-will_paginate#comment-209</link>
    </item>
    <item>
      <title>"Paginating acts_as_taggable with will_paginate" by P jam aka the nerb</title>
      <description>&lt;p&gt;Eric, a whole rails version later and using steroids, and still your 'eloquent' code snippet works great for me.&lt;/p&gt;

&lt;p&gt;since i'm trying to keep my plugins as natural as possible, i thank you.  oh and you too dave.&lt;/p&gt;</description>
      <pubDate>Thu, 27 Mar 2008 04:34:31 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:1a3033ef-4ab4-468c-84ac-0eb93bd050cb</guid>
      <link>http://blog.wolfman.com/articles/2007/07/30/paginating-acts_as_taggable-with-will_paginate#comment-208</link>
    </item>
    <item>
      <title>"Paginating acts_as_taggable with will_paginate" by Henry</title>
      <description>&lt;p&gt;i had an sql error using John's comment.  Aaron's solution seems to work though.&lt;/p&gt;</description>
      <pubDate>Sat, 05 Jan 2008 14:36:06 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:70e7be8c-0c9e-403c-9b6b-028c250530a6</guid>
      <link>http://blog.wolfman.com/articles/2007/07/30/paginating-acts_as_taggable-with-will_paginate#comment-191</link>
    </item>
    <item>
      <title>"Paginating acts_as_taggable with will_paginate" by goodwill</title>
      <description>&lt;p&gt;I tried John Wong's comment but seems not working... (Dave u are referring to this right?) &lt;/p&gt;

&lt;p&gt;I really think if such way would work its very clean.&lt;/p&gt;</description>
      <pubDate>Sat, 05 Jan 2008 01:37:06 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:544ddace-0b5c-4c17-a37d-b947359bacf6</guid>
      <link>http://blog.wolfman.com/articles/2007/07/30/paginating-acts_as_taggable-with-will_paginate#comment-190</link>
    </item>
    <item>
      <title>"Paginating acts_as_taggable with will_paginate" by wolfmanjm</title>
      <description>&lt;p&gt;the match_all option doesn't work on postgresql anyway, I found a different workaround that uses a subselect to find the ids, then looks up using IN (ids,..) if anyone needs it let me know and I'll post it.&lt;/p&gt;</description>
      <pubDate>Tue, 27 Nov 2007 18:17:06 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:46265190-a714-4016-98af-d64131ebfea3</guid>
      <link>http://blog.wolfman.com/articles/2007/07/30/paginating-acts_as_taggable-with-will_paginate#comment-160</link>
    </item>
    <item>
      <title>"Paginating acts_as_taggable with will_paginate" by Aaron H.</title>
      <description>&lt;p&gt;Dave,
I found this article while having the same problem.  &lt;/p&gt;

&lt;p&gt;The SQL error when using :match_all =&gt; true has to do with the will_paginate trying to count via the select created by acts_as_taggable.  My solution was to add the following line to the beginning of the wp_count! function in finder.rb of will_paginate:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;options[:select].sub!(/.*/, '\1.id') if options[:select] #count by id's, not wildcard (*)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will work unless the table you are counting does not have an id column, but using active record that should be extremely rare. If that's the case, you could always have it find the name of the class's key field.  &lt;/p&gt;</description>
      <pubDate>Mon, 26 Nov 2007 18:09:51 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:9b451d70-f269-415c-abf0-d28a08eb4f53</guid>
      <link>http://blog.wolfman.com/articles/2007/07/30/paginating-acts_as_taggable-with-will_paginate#comment-156</link>
    </item>
    <item>
      <title>"Paginating acts_as_taggable with will_paginate" by Dave</title>
      <description>&lt;p&gt;This works unless you have &lt;code&gt;:match_all&lt;/code&gt; =&gt; true in there.  Once you do that, a group by is added that causes &lt;code&gt;will_paginate&lt;/code&gt; to get a MySQL syntax error.  Still working on a way to fix it...&lt;/p&gt;</description>
      <pubDate>Fri, 19 Oct 2007 17:03:59 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:c8b84d06-e5bf-463f-af5d-bdecf2370c66</guid>
      <link>http://blog.wolfman.com/articles/2007/07/30/paginating-acts_as_taggable-with-will_paginate#comment-154</link>
    </item>
    <item>
      <title>"Paginating acts_as_taggable with will_paginate" by John Wong</title>
      <description>&lt;p&gt;Hey man....   seriously ..  u dont have to put so much work just to get it to work.
Just use &lt;code&gt;acts_as_taggable_on_sterioids&lt;/code&gt; ...&lt;/p&gt;

&lt;p&gt;And use 2 simple lines&lt;/p&gt;

&lt;pre&gt;&lt;code&gt; options = Car.find_options_for_tagged_with(params[:tag_name]).merge :page =&amp;gt; params[:page]
@cars = Car.paginate(options)
&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Wed, 12 Sep 2007 01:51:22 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:bfb37300-1f87-440d-9102-b078e75d50ce</guid>
      <link>http://blog.wolfman.com/articles/2007/07/30/paginating-acts_as_taggable-with-will_paginate#comment-140</link>
    </item>
    <item>
      <title>"Paginating acts_as_taggable with will_paginate" by Eric</title>
      <description>&lt;p&gt;I found this working with &lt;code&gt;acts_as_taggable&lt;/code&gt; and &lt;code&gt;will_paginate&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@events = Event.paginate_by_id(Event.find_tagged_with(params[:id]), :page =&amp;gt; params[:page])&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Maybe there is a more graceful way.&lt;/p&gt;</description>
      <pubDate>Wed, 15 Aug 2007 02:30:32 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:75687cf3-2b35-43da-aa2e-c363cf17f8aa</guid>
      <link>http://blog.wolfman.com/articles/2007/07/30/paginating-acts_as_taggable-with-will_paginate#comment-129</link>
    </item>
  </channel>
</rss>
