<?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>Sean&#039;s Blog &#187; created_at</title>
	<atom:link href="http://seanbehan.com/tag/created_at/feed/" rel="self" type="application/rss+xml" />
	<link>http://seanbehan.com</link>
	<description>Web Programming, Ruby on Rails, Wordpress, PHP from Burlington, Vermont</description>
	<lastBuildDate>Wed, 18 Jan 2012 21:44:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Descending Sort By in Model For Active Record Hash on Created_at attribute</title>
		<link>http://seanbehan.com/ruby-on-rails/descending-sort-by-in-model-for-active-record-hash-on-created_at-attribute/</link>
		<comments>http://seanbehan.com/ruby-on-rails/descending-sort-by-in-model-for-active-record-hash-on-created_at-attribute/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 19:08:48 +0000</pubDate>
		<dc:creator>bseanvt</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[active record]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[created_at]]></category>
		<category><![CDATA[sort_by]]></category>

		<guid isPermaLink="false">http://seanbehan.com/?p=614</guid>
		<description><![CDATA[If you have a couple collections from the database and you want to sort it without the help of Active Record, take a look at the sort_by method on Array type. I&#8217;ve used this before when I have a couple of collections which are slightly different but I need them in a chronological order. @posts_group_a [...]]]></description>
			<content:encoded><![CDATA[<div style="height:33px;" class="really_simple_share robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:px;">
				<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fseanbehan.com%2Fruby-on-rails%2Fdescending-sort-by-in-model-for-active-record-hash-on-created_at-attribute%2F&amp;layout=button_count&amp;show_faces=false&amp;width=&amp;action=like&amp;colorscheme=light&amp;send=false&amp;height=27" 
						scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:px; height:27px;" allowTransparency="true"></iframe>
				</div><div class="really_simple_share_twitter" style="width:px;">
					<a href="http://twitter.com/share" class="twitter-share-button" data-count="horizontal" 
						data-text="Descending Sort By in Model For Active Record Hash on Created_at attribute" data-url="http://seanbehan.com/ruby-on-rails/descending-sort-by-in-model-for-active-record-hash-on-created_at-attribute/" 
						data-via="" ></a> 
				</div></div>
		<div style="clear:both;"></div><p>If you have a couple collections from the database and you want to sort it without the help of Active Record, take a look at the sort_by method on Array type. I&#8217;ve used this before when I have a couple of collections which are slightly different but I need them in a chronological order.</p>
<pre class="wp-code-highlight prettyprint">

  @posts_group_a = Post.find :all, :conditions =&gt; [&quot;user_id = ?&quot;, current_user.id]
  @posts_group_b = Post.find :all, :conditions =&gt; [&quot;user_id = ?&quot;, friend_user.id]

  #merge the two arrays here
  @posts = @posts_group_a + @posts_group_b

  # notice the &quot;-&quot; is for descending order and the &quot;to_i&quot; casts the date time to an integer (required)
  @posts.sort_by {|post| - post.created_at.to_i}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://seanbehan.com/ruby-on-rails/descending-sort-by-in-model-for-active-record-hash-on-created_at-attribute/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

