<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tecno-Pedagogia &#187; pagination</title>
	<atom:link href="http://www.christopherslade.com/tag/pagination/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.christopherslade.com</link>
	<description>Random Thoughts on Computer Science Education, and Other Topics</description>
	<lastBuildDate>Fri, 05 Feb 2010 03:31:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rails Pagination with AJAX</title>
		<link>http://www.christopherslade.com/2009/04/rails-pagination-with-ajax/</link>
		<comments>http://www.christopherslade.com/2009/04/rails-pagination-with-ajax/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 01:04:24 +0000</pubDate>
		<dc:creator>cslade</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[pagination]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.christopherslade.com/?p=66</guid>
		<description><![CDATA[When I upgraded to Rails 2.0, I quickly found out that pagination was removed from the rails code base.  In order to get it you have to install a plugin.  After searching on the web I found two possible plugins: classic pagination, and will_paginate.  I choose will_paginate because it is more efficient and works directly [...]]]></description>
			<content:encoded><![CDATA[<p>When I upgraded to Rails 2.0, I quickly found out that pagination was removed from the rails code base.  In order to get it you have to install a plugin.  After searching on the web I found two possible plugins: classic pagination, and <a href="http://wiki.github.com/mislav/will_paginate">will_paginate</a>.  I choose will_paginate because it is more efficient and works directly with the model.</p>
<p>However, the author suggests not to use link_to_remote to implement an &#8220;AJAXified&#8221; pagination.  Instead he gives some pretty ugly javascript code that does it.  Since I am using a lot of javascript in other areas of my application, I was really hesitant to go down that path and possibly break my javascript functions.  I see his point, in that not everyone uses the prototype library, but I do.  So I came across <a href="http://weblog.redlinesoftware.com/2008/1/30/willpaginate-and-remote-links">Redline&#8217;s blog</a> to change my links to link_to_remote links.  But this violates the other reason the will_paginate&#8217;s author gives for not using link_to_remote &#8211; non-javascript browser support and search engine support.</p>
<p>After looking at the link_to_remote documentation, I found that you can replace the default anchor link location (href=&#8221;#&#8221;) with the same url the ajax call goes to.  This allows non-javascript enabled browsers and search engines to follow the links.  I just modified Redline&#8217;s render to add one extra option to set the href.  This is my renderer module:</p>
<pre># app/helpers/remote_link_renderer.rb

class RemoteLinkRenderer &lt; WillPaginate::LinkRenderer
  def prepare(collection, options, template)
     @remote = options.delete(:remote) || {}
     super
  end

protected
  def page_link(page, text, attributes = {})
     @template.link_to_remote(text, {:url =&gt; url_for(page),
          :method =&gt; :get}.merge(@remote), :href =&gt; url_for(page))
  end
end</pre>
<p>With that, javascript-enabled browsers will use make and use the AJAX calls, and non-javascript-enabled browsers and search engines will use the normal links.  This seems like the cleanest and most DRY way to get pagination with AJAX.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christopherslade.com/2009/04/rails-pagination-with-ajax/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
