<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>opensoul.org - acts_as_ferret will_paginate Changes</title>
  <id>tag:opensoul.org,2010:/2007/8/17/acts_as_ferret-will_paginate/changes</id>
  <generator version="0.8.0" uri="http://mephistoblog.com">Mephisto Drax</generator>
  <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate/changes.xml" rel="self" type="application/atom+xml"/>
  <link href="/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
  <updated>2009-05-07T13:59:31Z</updated>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>brandon</name>
    </author>
    <id>tag:opensoul.org,2009-05-07:536:4</id>
    <published>2007-08-17T04:21:00Z</published>
    <updated>2009-05-07T13:59:31Z</updated>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>acts_as_ferret will_paginate</title>
<content type="html">&lt;p&gt;+&lt;strong&gt;Update:&lt;/strong&gt; This is not needed with recent versions of acts_as_ferret.&lt;/p&gt;


	&lt;p&gt;Here&#8217;s a little nugget to add to &lt;a href=&quot;http://projects.jkraemer.net/acts_as_ferret/wiki&quot;&gt;acts_as_ferret&lt;/a&gt; to make your searches paginate with &lt;a href=&quot;http://errtheblog.com/post/4791&quot;&gt;will_paginate&lt;/a&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;module ActsAsFerret
  module ClassMethods
    def paginate_search(query, options = {})
      page, per_page, total = wp_parse_options(options)
      pager = WillPaginate::Collection.new(page, per_page, total)
      options.merge!(:offset =&amp;gt; pager.offset, :limit =&amp;gt; per_page)
      result = find_by_contents(query, options)
      returning WillPaginate::Collection.new(page, per_page, result.total_hits) do |pager|
        pager.replace result
      end
    end
  end
end&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;&lt;em&gt;Updated from Behrang&#8217;s comment based on changes to will_paginate.&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;There was a slight challenge in that will_paginate expects that you do one query to get the count, create a new collection object based on that count, and then perform the actual search.  But acts_as_ferret does it all in one method call, so I have to create a temporary collection object to get the offset, then do the search and create the collection object.  It&#8217;s a little messier than it needs to be, but it works.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;Product.paginate_search params[:q], :page =&amp;gt; params[:page]&lt;/code&gt;&lt;/pre&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>brandon</name>
    </author>
    <id>tag:opensoul.org,2008-03-14:413:3</id>
    <published>2007-08-17T04:21:00Z</published>
    <updated>2008-03-14T14:55:08Z</updated>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>acts_as_ferret will_paginate</title>
<content type="html">&lt;p&gt;Here&#8217;s a little nugget to add to &lt;a href=&quot;http://projects.jkraemer.net/acts_as_ferret/wiki&quot;&gt;acts_as_ferret&lt;/a&gt; to make your searches paginate with &lt;a href=&quot;http://errtheblog.com/post/4791&quot;&gt;will_paginate&lt;/a&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;module ActsAsFerret
  module ClassMethods
    def paginate_search(query, options = {})
      page, per_page, total = wp_parse_options(options)
      pager = WillPaginate::Collection.new(page, per_page, total)
      options.merge!(:offset =&amp;gt; pager.offset, :limit =&amp;gt; per_page)
      result = find_by_contents(query, options)
      returning WillPaginate::Collection.new(page, per_page, result.total_hits) do |pager|
        pager.replace result
      end
    end
  end
end&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;&lt;em&gt;Updated from Behrang&#8217;s comment based on changes to will_paginate.&lt;/em&gt;&lt;/p&gt;


	&lt;p&gt;There was a slight challenge in that will_paginate expects that you do one query to get the count, create a new collection object based on that count, and then perform the actual search.  But acts_as_ferret does it all in one method call, so I have to create a temporary collection object to get the offset, then do the search and create the collection object.  It&#8217;s a little messier than it needs to be, but it works.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;Product.paginate_search params[:q], :page =&amp;gt; params[:page]&lt;/code&gt;&lt;/pre&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>brandon</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:361:2</id>
    <published>2007-08-17T04:21:53Z</published>
    <updated>2007-08-17T04:57:28Z</updated>
    <link href="http://opensoul.org/2007/8/17/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>acts_as_ferret will_paginate</title>
<content type="html">&lt;p&gt;Here&#8217;s a little nugget to add to &lt;a href=&quot;http://projects.jkraemer.net/acts_as_ferret/wiki&quot;&gt;acts_as_ferret&lt;/a&gt; to make your searches paginate with &lt;a href=&quot;http://errtheblog.com/post/4791&quot;&gt;will_paginate&lt;/a&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;module ActsAsFerret
  module ClassMethods
    def paginate_search(query, options = {})
      options, page, per_page = wp_parse_options!(options)
      pager = WillPaginate::Collection.new(page, per_page, nil)
      options.merge!(:offset =&amp;gt; pager.offset, :limit =&amp;gt; per_page)
      result = result = find_by_contents(query, options)
      returning WillPaginate::Collection.new(page, per_page, result.total_hits) do |pager|
        pager.replace result
      end
    end
  end
end&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;There was a slight challenge in that will_paginate expects that you do one query to get the count, create a new collection object based on that count, and then perform the actual search.  But acts_as_ferret does it all in one method call, so I have to create a temporary collection object to get the offset, then do the search and create the collection object.  It&#8217;s a little messier than it needs to be, but it works.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;Product.paginate_search params[:q], :page =&amp;gt; params[:page]&lt;/code&gt;&lt;/pre&gt;</content>  </entry>
  <entry xml:base="http://opensoul.org/">
    <author>
      <name>brandon</name>
    </author>
    <id>tag:opensoul.org,2007-08-17:360:1</id>
    <updated>2007-08-17T04:53:21Z</updated>
    <link href="http://opensoul.org/2010/6/10/acts_as_ferret-will_paginate" rel="alternate" type="text/html"/>
    <title>acts_as_ferret will_paginate</title>
<content type="html">&lt;p&gt;Here&#8217;s a little nugget to add to &lt;a href=&quot;http://projects.jkraemer.net/acts_as_ferret/wiki&quot;&gt;acts_as_ferret&lt;/a&gt; to make your searches paginate with &lt;a href=&quot;http://errtheblog.com/post/4791&quot;&gt;will_paginate&lt;/a&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;module ActsAsFerret
  module ClassMethods
    def paginate_search(query, options = {})
      options, page, per_page = wp_parse_options!(options)
      pager = WillPaginate::Collection.new(page, per_page, nil)
      options.merge!(:offset =&amp;gt; pager.offset, :limit =&amp;gt; per_page)
      result = result = find_by_contents(query, options)
      returning WillPaginate::Collection.new(page, per_page, result.total_hits) do |pager|
        pager.replace result
      end
    end
  end
end&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;There was a slight challenge in that will_paginate expects that you do one query to get the count, create a new collection object based on that count, and then perform the actual search.  But acts_as_ferret does it all in one method call, so I have to create a temporary collection object to get the offset, then do the search and create the collection object.  It&#8217;s a little messier than it needs to be, but it works.&lt;/p&gt;</content>  </entry>
</feed>
