<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Pagination with acts_as_taggable_on_steroids, acts_as_ferret, and will_paginate</title>
	<atom:link href="http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/</link>
	<description>Ruby on Rails web application development for Dallas/Fort Worth and all of North Texas.</description>
	<pubDate>Fri, 05 Sep 2008 17:48:46 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Nathan</title>
		<link>http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-43</link>
		<dc:creator>Nathan</dc:creator>
		<pubDate>Wed, 28 May 2008 16:34:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-43</guid>
		<description>Jeremy please be more specific, what should the name of your method be called?</description>
		<content:encoded><![CDATA[<p>Jeremy please be more specific, what should the name of your method be called?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy</title>
		<link>http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-40</link>
		<dc:creator>Jeremy</dc:creator>
		<pubDate>Thu, 21 Feb 2008 20:53:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-40</guid>
		<description>Woops, bit of a mistake there... the method here is called _paginate_tagged_with... will_paginate will send paginate_by_tag to find_all_by_tag, and paginate_tagged_with to find_tagged_with (which actually exists, but won't get you proper pagination!).</description>
		<content:encoded><![CDATA[<p>Woops, bit of a mistake there&#8230; the method here is called _paginate_tagged_with&#8230; will_paginate will send paginate_by_tag to find_all_by_tag, and paginate_tagged_with to find_tagged_with (which actually exists, but won&#8217;t get you proper pagination!).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeremy</title>
		<link>http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-39</link>
		<dc:creator>Jeremy</dc:creator>
		<pubDate>Thu, 21 Feb 2008 20:48:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-39</guid>
		<description>I had to modify the taggable_paging fix a bit to make it work with the latest version of will_paginate.  This solution will also accept all the same options as find_tagged_with.

Oh, and this drove me crazy... naming the method "paginate_by_tag" won't work, because will_paginate, being too clever for its own good, will intercept the method_missing call before it gets to the module and look for find_all_by_tag.  I renamed the method to _paginate_by_tag to get around this (I know there must be a more elegant solution).  


module ActiveRecord
  module Acts #:nodoc:
    module Taggable #:nodoc:
      module SingletonMethods
        
        def count_tagged_with(*args)
          options = find_options_for_find_tagged_with(*args)
          options.blank? ? 0 : count("#{table_name}.id", options.merge(:select =&#62; nil, :distinct =&#62; true))     
        end

        def _paginate_tagged_with(tags, options = {})
          page, per_page = wp_parse_options!(options)
          offset = (page.to_i - 1) * per_page
          count  = count_tagged_with(tags, options)
          options.merge!(:offset =&#62; offset, :limit =&#62; per_page.to_i)
          items  = find_tagged_with(tags, options)
          returning WillPaginate::Collection.new(page, per_page, count) do &#124;p&#124;
            p.replace items
          end
        end
       
      end
    end
  end
end
</description>
		<content:encoded><![CDATA[<p>I had to modify the taggable_paging fix a bit to make it work with the latest version of will_paginate.  This solution will also accept all the same options as find_tagged_with.</p>
<p>Oh, and this drove me crazy&#8230; naming the method &#8220;paginate_by_tag&#8221; won&#8217;t work, because will_paginate, being too clever for its own good, will intercept the method_missing call before it gets to the module and look for find_all_by_tag.  I renamed the method to _paginate_by_tag to get around this (I know there must be a more elegant solution).  </p>
<p>module ActiveRecord<br />
  module Acts #:nodoc:<br />
    module Taggable #:nodoc:<br />
      module SingletonMethods</p>
<p>        def count_tagged_with(*args)<br />
          options = find_options_for_find_tagged_with(*args)<br />
          options.blank? ? 0 : count(&#8221;#{table_name}.id&#8221;, options.merge(:select =&gt; nil, :distinct =&gt; true))<br />
        end</p>
<p>        def _paginate_tagged_with(tags, options = {})<br />
          page, per_page = wp_parse_options!(options)<br />
          offset = (page.to_i - 1) * per_page<br />
          count  = count_tagged_with(tags, options)<br />
          options.merge!(:offset =&gt; offset, :limit =&gt; per_page.to_i)<br />
          items  = find_tagged_with(tags, options)<br />
          returning WillPaginate::Collection.new(page, per_page, count) do |p|<br />
            p.replace items<br />
          end<br />
        end</p>
<p>      end<br />
    end<br />
  end<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: marc</title>
		<link>http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-38</link>
		<dc:creator>marc</dc:creator>
		<pubDate>Thu, 21 Feb 2008 18:16:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-38</guid>
		<description>Thanks!  I shud have looked harder for it.  =)</description>
		<content:encoded><![CDATA[<p>Thanks!  I shud have looked harder for it.  =)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl</title>
		<link>http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-37</link>
		<dc:creator>Karl</dc:creator>
		<pubDate>Thu, 21 Feb 2008 13:39:08 +0000</pubDate>
		<guid isPermaLink="false">http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-37</guid>
		<description>excuse me, typographic error, I try it again:

&#60;%= will_paginate @members %&#62;

Result: something like
« Previous 1 2 3 4 5 6 7 8 9 10 11 Next »</description>
		<content:encoded><![CDATA[<p>excuse me, typographic error, I try it again:</p>
<p>&lt;%= will_paginate @members %&gt;</p>
<p>Result: something like<br />
« Previous 1 2 3 4 5 6 7 8 9 10 11 Next »</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karl</title>
		<link>http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-36</link>
		<dc:creator>Karl</dc:creator>
		<pubDate>Thu, 21 Feb 2008 13:27:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-36</guid>
		<description>Marc, I tried:
     
Result: something like
     « Previous 1 2 3 4 5 6 7 8 9 10 11 Next »</description>
		<content:encoded><![CDATA[<p>Marc, I tried:</p>
<p>Result: something like<br />
     « Previous 1 2 3 4 5 6 7 8 9 10 11 Next »</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: marc</title>
		<link>http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-35</link>
		<dc:creator>marc</dc:creator>
		<pubDate>Tue, 19 Feb 2008 16:35:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-35</guid>
		<description>I have included the following in my controller.

@entries = Entry.paginate_by_tag @tag.name,
                                     :order =&#62; 'entries.created_at DESC',
                                     :page =&#62; params[:page],
                                     :per_page =&#62; 20

Now, how do I get to the next page?  What's the code in the view?  Can anyone help me?  Thanks!</description>
		<content:encoded><![CDATA[<p>I have included the following in my controller.</p>
<p>@entries = Entry.paginate_by_tag @tag.name,<br />
                                     :order =&gt; &#8216;entries.created_at DESC&#8217;,<br />
                                     :page =&gt; params[:page],<br />
                                     :per_page =&gt; 20</p>
<p>Now, how do I get to the next page?  What&#8217;s the code in the view?  Can anyone help me?  Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: karl</title>
		<link>http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-32</link>
		<dc:creator>karl</dc:creator>
		<pubDate>Sun, 10 Feb 2008 20:33:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-32</guid>
		<description>After having deleted 'option' in: "options, page, per_page = wp_parse_options!(options)" --- comment of Francois — January 20, 2008 --- rails finished croaking.

Now I wanted the field 'lemma' of my database (an old german dictionary) alphabetically sorted. Following http://www.railsenvy.com/2007/2/19/acts-as-ferret-tutorial
to rebuild the index, I finally wrote in (or copied into) the Controller:

sorter = Ferret::Search::SortField.new(:lemma_for_sort, :reverse =&#62; false)
@members = Member.paginate_search params[:query],
:page =&#62; params[:page] ,
:per_page =&#62; 25, 
:sort =&#62; sorter

"lemma_for_sort" (in the tutorial "title_for_sort"): a method defined in the model - see tutorial.

Oh wonder, it works! But only thanks to the  great help of Geoffrey and his commentators.</description>
		<content:encoded><![CDATA[<p>After having deleted &#8216;option&#8217; in: &#8220;options, page, per_page = wp_parse_options!(options)&#8221; &#8212; comment of Francois — January 20, 2008 &#8212; rails finished croaking.</p>
<p>Now I wanted the field &#8216;lemma&#8217; of my database (an old german dictionary) alphabetically sorted. Following <a href="http://www.railsenvy.com/2007/2/19/acts-as-ferret-tutorial" rel="nofollow">http://www.railsenvy.com/2007/2/19/acts-as-ferret-tutorial</a><br />
to rebuild the index, I finally wrote in (or copied into) the Controller:</p>
<p>sorter = Ferret::Search::SortField.new(:lemma_for_sort, :reverse =&gt; false)<br />
@members = Member.paginate_search params[:query],<br />
:page =&gt; params[:page] ,<br />
:per_page =&gt; 25,<br />
:sort =&gt; sorter</p>
<p>&#8220;lemma_for_sort&#8221; (in the tutorial &#8220;title_for_sort&#8221;): a method defined in the model - see tutorial.</p>
<p>Oh wonder, it works! But only thanks to the  great help of Geoffrey and his commentators.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim Haines</title>
		<link>http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-31</link>
		<dc:creator>Tim Haines</dc:creator>
		<pubDate>Thu, 07 Feb 2008 01:47:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-31</guid>
		<description>I adapted it for the 1 Feb 08 version of will_paginate, and adjusted the count to also consider conditions.  I'm new at this so keen for any feedback - but the file I have in the lib folder is:

module ActiveRecord
  module Acts #:nodoc:
    module Taggable #:nodoc:
      module SingletonMethods
        # paginate a call to find_tagged_with
        # tag is the tag to find
        # options is the option to use for pagination (:page, :per_page) and for find_tagged_with
        def paginate_by_tag(tag, options = {})
          page, per_page, total = wp_parse_options!(options)
          if(options[:conditions].blank?)
            counts = tag_counts(:conditions =&#62; sanitize_sql("tags.name = '" + tag + "'"))
          else
            counts = tag_counts(:conditions =&#62; sanitize_sql(options[:conditions] + " and tags.name = '" + tag + "'"))
          end
          
          count = 0
          count = counts[0].count if counts.size == 1
          
          offset = (page.to_i - 1) * per_page
          options.merge!(:offset =&#62; offset, :limit =&#62; per_page.to_i)
          items = find_tagged_with(tag, options)
          returning WillPaginate::Collection.new(page, per_page, count) do &#124;p&#124;
            p.replace items
          end
        end
      end
    end
  end
end</description>
		<content:encoded><![CDATA[<p>I adapted it for the 1 Feb 08 version of will_paginate, and adjusted the count to also consider conditions.  I&#8217;m new at this so keen for any feedback - but the file I have in the lib folder is:</p>
<p>module ActiveRecord<br />
  module Acts #:nodoc:<br />
    module Taggable #:nodoc:<br />
      module SingletonMethods<br />
        # paginate a call to find_tagged_with<br />
        # tag is the tag to find<br />
        # options is the option to use for pagination (:page, :per_page) and for find_tagged_with<br />
        def paginate_by_tag(tag, options = {})<br />
          page, per_page, total = wp_parse_options!(options)<br />
          if(options[:conditions].blank?)<br />
            counts = tag_counts(:conditions =&gt; sanitize_sql(&#8221;tags.name = &#8216;&#8221; + tag + &#8220;&#8216;&#8221;))<br />
          else<br />
            counts = tag_counts(:conditions =&gt; sanitize_sql(options[:conditions] + &#8221; and tags.name = &#8216;&#8221; + tag + &#8220;&#8216;&#8221;))<br />
          end</p>
<p>          count = 0<br />
          count = counts[0].count if counts.size == 1</p>
<p>          offset = (page.to_i - 1) * per_page<br />
          options.merge!(:offset =&gt; offset, :limit =&gt; per_page.to_i)<br />
          items = find_tagged_with(tag, options)<br />
          returning WillPaginate::Collection.new(page, per_page, count) do |p|<br />
            p.replace items<br />
          end<br />
        end<br />
      end<br />
    end<br />
  end<br />
end</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Francois</title>
		<link>http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-30</link>
		<dc:creator>Francois</dc:creator>
		<pubDate>Mon, 21 Jan 2008 02:44:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.mckinneystation.com/2007/08/20/pagination-with-acts_as_taggable_on_steroids-acts_as_ferret-and-will_paginate/#comment-30</guid>
		<description>The most recent version of will _paginate has changed sufficiently to make the above examples break. Specifically the wp_parse_options! method no longer returns [options, page, per_page, total]. Intead it simply returns [page, per_page, total].</description>
		<content:encoded><![CDATA[<p>The most recent version of will _paginate has changed sufficiently to make the above examples break. Specifically the wp_parse_options! method no longer returns [options, page, per_page, total]. Intead it simply returns [page, per_page, total].</p>
]]></content:encoded>
	</item>
</channel>
</rss>
