<?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: How to use will_paginate with non-ActiveRecord collection/array</title>
	<atom:link href="http://www.pathf.com/blogs/2008/06/how-to-use-will_paginate-with-non-activerecord-collectionarray/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pathf.com/blogs/2008/06/how-to-use-will_paginate-with-non-activerecord-collectionarray/</link>
	<description>Running commentary about agile development, user experience design and Ajax.</description>
	<lastBuildDate>Fri, 05 Mar 2010 19:33:43 -0600</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
	<item>
		<title>By: Javix</title>
		<link>http://www.pathf.com/blogs/2008/06/how-to-use-will_paginate-with-non-activerecord-collectionarray/comment-page-1/#comment-7979</link>
		<dc:creator>Javix</dc:creator>
		<pubDate>Mon, 30 Nov 2009 09:32:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=955#comment-7979</guid>
		<description>I can&#039;t figure out how to use the pagination with an existing array of objects got from has_many associations. So, I have Enterprise model and Service model. Enterprise has_many :services. I&#039;d like to show services for every enterprise; In my ServicesController in index action I do:
before_filter : find_client
def index
@services = @client.services
end

private
def find_client
@client = Client.find(:client_id)
end
How is it possible? If try to use like that:
@services = @client.services.paginate :page =&gt; params[:page], :order =&gt; &#039;created_at&#039;, :per_page =&gt; 20

I get:

 NoMethodError in Enterprises#show

Showing app/views/enterprises/show.html.erb where line #21 raised:

undefined method `total_pages&#039; for #

Extracted source (around line #21):

18:      &quot;/services/service&quot;,
19:       :collection =&gt; @enterprise.services, :locals=&gt; {:client =&gt; @enterprise} %&gt;
20:   
21:   
22: 
23: 
24:    &#124;</description>
		<content:encoded><![CDATA[<p>I can&#8217;t figure out how to use the pagination with an existing array of objects got from has_many associations. So, I have Enterprise model and Service model. Enterprise has_many :services. I&#8217;d like to show services for every enterprise; In my ServicesController in index action I do:<br />
before_filter : find_client<br />
def index<br />
@services = @client.services<br />
end</p>
<p>private<br />
def find_client<br />
@client = Client.find(:client_id)<br />
end<br />
How is it possible? If try to use like that:<br />
@services = @client.services.paginate :page =&gt; params[:page], <img src='http://www.pathf.com/blogs/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> rder =&gt; &#8216;created_at&#8217;, :per_page =&gt; 20</p>
<p>I get:</p>
<p> NoMethodError in Enterprises#show</p>
<p>Showing app/views/enterprises/show.html.erb where line #21 raised:</p>
<p>undefined method `total_pages&#8217; for #</p>
<p>Extracted source (around line #21):</p>
<p>18:      &#8220;/services/service&#8221;,<br />
19:       :collection =&gt; @enterprise.services, :locals=&gt; {:client =&gt; @enterprise} %&gt;<br />
20:<br />
21:<br />
22:<br />
23:<br />
24:    |</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: amit</title>
		<link>http://www.pathf.com/blogs/2008/06/how-to-use-will_paginate-with-non-activerecord-collectionarray/comment-page-1/#comment-6251</link>
		<dc:creator>amit</dc:creator>
		<pubDate>Thu, 09 Apr 2009 23:32:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=955#comment-6251</guid>
		<description>Thanks works like a charm. I used the way you describe here</description>
		<content:encoded><![CDATA[<p>Thanks works like a charm. I used the way you describe here</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: s!ck</title>
		<link>http://www.pathf.com/blogs/2008/06/how-to-use-will_paginate-with-non-activerecord-collectionarray/comment-page-1/#comment-5834</link>
		<dc:creator>s!ck</dc:creator>
		<pubDate>Thu, 12 Feb 2009 00:41:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=955#comment-5834</guid>
		<description>hey guys, nice post. i using rails to build a client which only consumes restful webservice with activeresource, so i deactivated activerecord. i&#039;m getting an array of activeresource object limited by :page and :per_page an so on. if i try to call will_paginate @results in the view it gives me an NoMethodError. In the controller i&#039;m using that WillPaginate::Collection.create(...) and it doesn&#039;t complain. but if i activate activerecord everything works. how can i say will_paginate not to be dependent on activerecord :D do i really have to patch it myself?</description>
		<content:encoded><![CDATA[<p>hey guys, nice post. i using rails to build a client which only consumes restful webservice with activeresource, so i deactivated activerecord. i&#8217;m getting an array of activeresource object limited by :page and :per_page an so on. if i try to call will_paginate @results in the view it gives me an NoMethodError. In the controller i&#8217;m using that WillPaginate::Collection.create(&#8230;) and it doesn&#8217;t complain. but if i activate activerecord everything works. how can i say will_paginate not to be dependent on activerecord <img src='http://www.pathf.com/blogs/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  do i really have to patch it myself?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shawn</title>
		<link>http://www.pathf.com/blogs/2008/06/how-to-use-will_paginate-with-non-activerecord-collectionarray/comment-page-1/#comment-4290</link>
		<dc:creator>shawn</dc:creator>
		<pubDate>Thu, 27 Nov 2008 01:16:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=955#comment-4290</guid>
		<description>Found it:

http://mislav.uniqpath.com/static/will_paginate/doc/

2.2.0, released 2008-04-07 API changes

Remove old, deprecated style of calling Array#paginate as &quot;paginate(page, per_page)&quot;. 

If you want to specify :page, :per_page or :total_entries, use a parameter hash.</description>
		<content:encoded><![CDATA[<p>Found it:</p>
<p><a href="http://mislav.uniqpath.com/static/will_paginate/doc/" rel="nofollow">http://mislav.uniqpath.com/static/will_paginate/doc/</a></p>
<p>2.2.0, released 2008-04-07 API changes</p>
<p>Remove old, deprecated style of calling Array#paginate as &#8220;paginate(page, per_page)&#8221;. </p>
<p>If you want to specify :page, :per_page or :total_entries, use a parameter hash.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: shawn</title>
		<link>http://www.pathf.com/blogs/2008/06/how-to-use-will_paginate-with-non-activerecord-collectionarray/comment-page-1/#comment-4289</link>
		<dc:creator>shawn</dc:creator>
		<pubDate>Thu, 27 Nov 2008 01:14:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=955#comment-4289</guid>
		<description>Am I the only one getting the exception: Wrong number of arguments (2 for 1) trying this:

@page_results = @posts.paginate(params[:current_page], params[:per_page])

Thanks! :)</description>
		<content:encoded><![CDATA[<p>Am I the only one getting the exception: Wrong number of arguments (2 for 1) trying this:</p>
<p>@page_results = @posts.paginate(params[:current_page], params[:per_page])</p>
<p>Thanks! <img src='http://www.pathf.com/blogs/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Iain</title>
		<link>http://www.pathf.com/blogs/2008/06/how-to-use-will_paginate-with-non-activerecord-collectionarray/comment-page-1/#comment-3546</link>
		<dc:creator>Iain</dc:creator>
		<pubDate>Tue, 07 Oct 2008 09:11:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=955#comment-3546</guid>
		<description>Yeah I looked for hours before finding this. And it was just what I needed. Thanks alot</description>
		<content:encoded><![CDATA[<p>Yeah I looked for hours before finding this. And it was just what I needed. Thanks alot</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: boblu</title>
		<link>http://www.pathf.com/blogs/2008/06/how-to-use-will_paginate-with-non-activerecord-collectionarray/comment-page-1/#comment-3364</link>
		<dc:creator>boblu</dc:creator>
		<pubDate>Fri, 12 Sep 2008 01:57:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=955#comment-3364</guid>
		<description>Thank you so much. I googled for a whole day, and eventually I found your post.  And your method solved all the problems I need to tack! Cheer!</description>
		<content:encoded><![CDATA[<p>Thank you so much. I googled for a whole day, and eventually I found your post.  And your method solved all the problems I need to tack! Cheer!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Lucraft</title>
		<link>http://www.pathf.com/blogs/2008/06/how-to-use-will_paginate-with-non-activerecord-collectionarray/comment-page-1/#comment-3216</link>
		<dc:creator>Daniel Lucraft</dc:creator>
		<pubDate>Thu, 28 Aug 2008 12:28:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.pathf.com/blogs/?p=955#comment-3216</guid>
		<description>Thanks this is exactly what I need.</description>
		<content:encoded><![CDATA[<p>Thanks this is exactly what I need.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Dynamic page generated in 0.260 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2010-03-13 16:31:20 -->
