<?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"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments on: Faster Pagination in Rails</title>
	<atom:link href="http://www.igvita.com/2006/09/10/faster-pagination-in-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.igvita.com/2006/09/10/faster-pagination-in-rails/</link>
	<description>A goal is a dream with a deadline.</description>
	<pubDate>Thu, 11 Mar 2010 05:03:10 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Thinking sphinx and paginating find &#124; Muziboo Development Blog</title>
		<link>http://www.igvita.com/2006/09/10/faster-pagination-in-rails/comment-page-5/#comment-193613</link>
		<dc:creator>Thinking sphinx and paginating find &#124; Muziboo Development Blog</dc:creator>
		<pubDate>Thu, 14 May 2009 17:33:22 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/10/faster-pagination-in-rails/#comment-193613</guid>
		<description>[...] the paginating find plugin to paginate results. You can find a great tutorial on paginating find at Ilya&#8217;s blog. Thinking sphinx however works only with will paginate plugin (atleast out of the box) and needs to [...]</description>
		<content:encoded><![CDATA[<p>[...] the paginating find plugin to paginate results. You can find a great tutorial on paginating find at Ilya&#8217;s blog. Thinking sphinx however works only with will paginate plugin (atleast out of the box) and needs to [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2006/09/10/faster-pagination-in-rails/comment-page-5/#comment-170635</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Thu, 19 Feb 2009 02:51:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/10/faster-pagination-in-rails/#comment-170635</guid>
		<description>You shouldn't need window_helper for will_pagination as it provides its own equivalent implementation as part of the plugin. Check the RDOC for some examples, and here is a screencast worth checking out: http://railscasts.com/episodes/51</description>
		<content:encoded><![CDATA[<p>You shouldn&#8217;t need window_helper for will_pagination as it provides its own equivalent implementation as part of the plugin. Check the RDOC for some examples, and here is a screencast worth checking out: <a href="http://railscasts.com/episodes/51" rel="nofollow">http://railscasts.com/episodes/51</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ahmadisa</title>
		<link>http://www.igvita.com/2006/09/10/faster-pagination-in-rails/comment-page-5/#comment-170195</link>
		<dc:creator>ahmadisa</dc:creator>
		<pubDate>Tue, 17 Feb 2009 08:14:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/10/faster-pagination-in-rails/#comment-170195</guid>
		<description>hi ilya ... 
can you help me??
how to implement window_helper.rb if I used will_pagination??</description>
		<content:encoded><![CDATA[<p>hi ilya &#8230;<br />
can you help me??<br />
how to implement window_helper.rb if I used will_pagination??</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zeba</title>
		<link>http://www.igvita.com/2006/09/10/faster-pagination-in-rails/comment-page-5/#comment-161389</link>
		<dc:creator>Zeba</dc:creator>
		<pubDate>Mon, 19 Jan 2009 09:48:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/10/faster-pagination-in-rails/#comment-161389</guid>
		<description>Thanks for the help Jeff...
I tried your solution but It didn't seem to take "ModelName.paginate_by_sql" and gives me an error as:
undefined method `paginate_by_sql' for #

In my environment.rb the code  I have is:
 module ActiveRecord  
     module ConnectionAdapters  
       class SQLServerAdapter  
          def add_limit_offset!(sql, options)  
            puts sql  
            options[:offset] &#124;&#124;= 0  
           options_limit = options[:limit] ? "TOP #{options[:limit]}" : ""  
            options[:order] &#124;&#124;= if order_by = sql.match(/ORDER BY(.*$)/i)  
                                 order_by[1]  
                              else  
                                 sql.match('FROM (.+?)\b')[1] + '.id'  
                              end  
           sql.sub!(/ORDER BY.*$/i, '')  
         sql.sub!(/SELECT/i, "SELECT #{options_limit} * FROM ( SELECT ROW_NUMBER() OVER( ORDER BY #{options[:order] } ) AS row_num, ")  
           sql &lt; #{options[:offset]}" 
           puts sql  
           sql  
         end  
       end  
     end  
  end  

and in my controller I have:

sql = "select d.id,d.name,d.description,d.image1,d.image2
    from disciplines d,disciplines_events ed
    where d.delete=1 and
    d.id=ed.discipline_id and
   ed.event_id=#{@id} order by name"
@disciplines = Discipline.paginate_by_sql [sql, true], :page =&gt; params[:page], :per_page =&gt; 2

I have mislav-will_paginate installed as a gem...
Can you please tell me where am I going wrong???
Thanks..</description>
		<content:encoded><![CDATA[<p>Thanks for the help Jeff&#8230;<br />
I tried your solution but It didn&#8217;t seem to take &#8220;ModelName.paginate_by_sql&#8221; and gives me an error as:<br />
undefined method `paginate_by_sql&#8217; for #</p>
<p>In my environment.rb the code  I have is:<br />
 module ActiveRecord<br />
     module ConnectionAdapters<br />
       class SQLServerAdapter<br />
          def add_limit_offset!(sql, options)<br />
            puts sql<br />
            options[:offset] ||= 0<br />
           options_limit = options[:limit] ? &#8220;TOP #{options[:limit]}&#8221; : &#8220;&#8221;<br />
            options[:order] ||= if order_by = sql.match(/ORDER BY(.*$)/i)<br />
                                 order_by[1]<br />
                              else<br />
                                 sql.match(&#8217;FROM (.+?)\b&#8217;)[1] + &#8216;.id&#8217;<br />
                              end<br />
           sql.sub!(/ORDER BY.*$/i, &#8221;)<br />
         sql.sub!(/SELECT/i, &#8220;SELECT #{options_limit} * FROM ( SELECT ROW_NUMBER() OVER( ORDER BY #{options[:order] } ) AS row_num, &#8220;)<br />
           sql &lt; #{options[:offset]}&#8221;<br />
           puts sql<br />
           sql<br />
         end<br />
       end<br />
     end<br />
  end  </p>
<p>and in my controller I have:</p>
<p>sql = &#8220;select d.id,d.name,d.description,d.image1,d.image2<br />
    from disciplines d,disciplines_events ed<br />
    where d.delete=1 and<br />
    d.id=ed.discipline_id and<br />
   ed.event_id=#{@id} order by name&#8221;<br />
@disciplines = Discipline.paginate_by_sql [sql, true], :page =&gt; params[:page], :per_page =&gt; 2</p>
<p>I have mislav-will_paginate installed as a gem&#8230;<br />
Can you please tell me where am I going wrong???<br />
Thanks..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Doyle</title>
		<link>http://www.igvita.com/2006/09/10/faster-pagination-in-rails/comment-page-5/#comment-160910</link>
		<dc:creator>Jeff Doyle</dc:creator>
		<pubDate>Fri, 16 Jan 2009 15:33:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/10/faster-pagination-in-rails/#comment-160910</guid>
		<description>Zeba - you need to provide the :page and :per_page args yourself. Try something like:

&lt;code&gt;
@results = Page.paginate_by_sql ["select blahs.* from ... where stuff=?", sql_arg], :page =&gt; params[:page], :per_page =&gt; 10
&lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Zeba - you need to provide the :page and :per_page args yourself. Try something like:</p>
<p><code><br />
@results = Page.paginate_by_sql ["select blahs.* from ... where stuff=?", sql_arg], :page =&gt; params[:page], :per_page =&gt; 10<br />
</code></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zeba</title>
		<link>http://www.igvita.com/2006/09/10/faster-pagination-in-rails/comment-page-4/#comment-160892</link>
		<dc:creator>Zeba</dc:creator>
		<pubDate>Fri, 16 Jan 2009 09:29:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/10/faster-pagination-in-rails/#comment-160892</guid>
		<description>Hi..
I need some help..
Can you tell me how can I paginate on custom queries???
I tried paginate_by_sql and paginate_from_sql...
But both didn't work...  :((
Is there any way I can pass custom queries to the will_paginate plugin...???
Thanks in advance...</description>
		<content:encoded><![CDATA[<p>Hi..<br />
I need some help..<br />
Can you tell me how can I paginate on custom queries???<br />
I tried paginate_by_sql and paginate_from_sql&#8230;<br />
But both didn&#8217;t work&#8230;  :((<br />
Is there any way I can pass custom queries to the will_paginate plugin&#8230;???<br />
Thanks in advance&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: elise</title>
		<link>http://www.igvita.com/2006/09/10/faster-pagination-in-rails/comment-page-4/#comment-111040</link>
		<dc:creator>elise</dc:creator>
		<pubDate>Wed, 13 Aug 2008 11:31:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/10/faster-pagination-in-rails/#comment-111040</guid>
		<description>There is a way for ultrasphinx:
see http://blog.aisleten.com/2008/04/19/hacking-the-ultrasphinx-plugin-to-work-with-paginating_find/
basically a wrapper round the corresponding methods of will_paginate.  Ultrasphinx doesn't use will_paginate directly, but defines the same methods.

Also you need to apply the pagination (page_count etc) onto the search itself, not the result (since with ultrasphinx you create a search object and then run it to get results).

I recently switched to ultrasphinx, while still using above pagination.  Ferret is just too unstable.</description>
		<content:encoded><![CDATA[<p>There is a way for ultrasphinx:<br />
see <a href="http://blog.aisleten.com/2008/04/19/hacking-the-ultrasphinx-plugin-to-work-with-paginating_find/" rel="nofollow">http://blog.aisleten.com/2008/04/19/hacking-the-ultrasphinx-plugin-to-work-with-paginating_find/</a><br />
basically a wrapper round the corresponding methods of will_paginate.  Ultrasphinx doesn&#8217;t use will_paginate directly, but defines the same methods.</p>
<p>Also you need to apply the pagination (page_count etc) onto the search itself, not the result (since with ultrasphinx you create a search object and then run it to get results).</p>
<p>I recently switched to ultrasphinx, while still using above pagination.  Ferret is just too unstable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2006/09/10/faster-pagination-in-rails/comment-page-4/#comment-109738</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Sat, 09 Aug 2008 18:48:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/10/faster-pagination-in-rails/#comment-109738</guid>
		<description>Richard, I think ultrasphinx is 'will_paginate' aware. Take a look at that plugin, it should be functionally equivalent and be easy to integrate.</description>
		<content:encoded><![CDATA[<p>Richard, I think ultrasphinx is &#8216;will_paginate&#8217; aware. Take a look at that plugin, it should be functionally equivalent and be easy to integrate.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard</title>
		<link>http://www.igvita.com/2006/09/10/faster-pagination-in-rails/comment-page-4/#comment-109084</link>
		<dc:creator>Richard</dc:creator>
		<pubDate>Fri, 08 Aug 2008 02:42:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/10/faster-pagination-in-rails/#comment-109084</guid>
		<description>Any ideas on how to work this plugin with the Ultrasphinx search plugin?</description>
		<content:encoded><![CDATA[<p>Any ideas on how to work this plugin with the Ultrasphinx search plugin?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ilya Grigorik</title>
		<link>http://www.igvita.com/2006/09/10/faster-pagination-in-rails/comment-page-4/#comment-107423</link>
		<dc:creator>Ilya Grigorik</dc:creator>
		<pubDate>Sun, 27 Jul 2008 23:53:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.igvita.com/blog/2006/09/10/faster-pagination-in-rails/#comment-107423</guid>
		<description>Owen, window_helper function should reside in the application_helper file, and the partial you can put in a 'shared' directory, so you can reuse it in different models. Having said that, if you're only paginating one model, you can simply put it in the same folder. Last but not least, take a look at the updated code Jeff has shared few messages below.

Jeff, thanks a lot for sharing your code!</description>
		<content:encoded><![CDATA[<p>Owen, window_helper function should reside in the application_helper file, and the partial you can put in a &#8217;shared&#8217; directory, so you can reuse it in different models. Having said that, if you&#8217;re only paginating one model, you can simply put it in the same folder. Last but not least, take a look at the updated code Jeff has shared few messages below.</p>
<p>Jeff, thanks a lot for sharing your code!</p>
]]></content:encoded>
	</item>
</channel>
</rss>
