<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Inigral Inc.</title>
	<atom:link href="http://inigral.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://inigral.wordpress.com</link>
	<description>The Social Web for Education</description>
	<lastBuildDate>Fri, 05 Sep 2008 21:25:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='inigral.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Inigral Inc.</title>
		<link>http://inigral.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://inigral.wordpress.com/osd.xml" title="Inigral Inc." />
	<atom:link rel='hub' href='http://inigral.wordpress.com/?pushpress=hub'/>
		<item>
		<title>has_many :through polymorphic with STI</title>
		<link>http://inigral.wordpress.com/2008/09/05/has_many-through-polymorphic-with-sti/</link>
		<comments>http://inigral.wordpress.com/2008/09/05/has_many-through-polymorphic-with-sti/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 21:19:40 +0000</pubDate>
		<dc:creator>Joseph Sofaer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[has_many :through polymorphic]]></category>
		<category><![CDATA[single table inheritance]]></category>
		<category><![CDATA[source_type]]></category>
		<category><![CDATA[STI]]></category>

		<guid isPermaLink="false">http://inigral.wordpress.com/?p=25</guid>
		<description><![CDATA[An example of using has_many :through polymorphic with single table inheritance on either or both sides of the polymorphic through table. You need the :souce_type key.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=inigral.wordpress.com&amp;blog=4166375&amp;post=25&amp;subd=inigral&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The code for has_many :through polymorphic is pretty straightforward but what if you are using Single Table Inheritance (STI) on either or both sides of the polymorphic through table?</p>
<p>There were a number of painful hacks to make this work until a patch to ActiveRecord by Trevor Squires added the :source_type key to has_many :through polymorphic (hmtp). Check it out here: <a href="http://dev.rubyonrails.org/ticket/7143">[PATCH] allow polymorphic :source for has_many :through</a></p>
<p>The main purpose of this blog post is to write up an example of using :source_type in the hope that people won&#8217;t get tripped up by out-of-date blog posts which delt with hmtp before the :source_type patch.</p>
<h3>The Scenario:</h3>
<p>Your web application has Users and Organizations and users belong to an organization through Memberships.<br />
This is a typical example of where you might use has_many :through. But what if you have many subclasses of users &#8211; like Student and Admin &#8211; and/or you have subclasses of Organizations &#8211; like StudentOrganization and AthleticTeam. To make this work you&#8217;ll need the :source_type key. Once you have that it&#8217;s quite simple:</p>
<h3>The Key Models:</h3>
<p><code>class User &lt; ActiveRecord::Base<br />
has_many :memberships<br />
has_many <img src='http://s1.wp.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> rganizations, :through =&gt; :memberships, :source =&gt; :member_of, :source_type =&gt; 'Organization'<br />
end</code></p>
<p><code>class Membership &lt; ActiveRecord::Base<br />
belongs_to :user<br />
belongs_to :member_of, :polymorphic =&gt; true<br />
end</code></p>
<p><code>class Organization &lt; ActiveRecord::Base<br />
has_many :memberships, :as =&gt; :member_of<br />
has_many :users, :through =&gt; :memberships<br />
end</code></p>
<h3>The Other Models:</h3>
<p><code>class Student &lt; User<br />
end</code><br />
<code>class Admin &lt; User<br />
end</code></p>
<p><code>class StudentOrganization &lt; Organization<br />
end</code></p>
<p><code>class AthleticTeam &lt; Organization<br />
end</code></p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/inigral.wordpress.com/25/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/inigral.wordpress.com/25/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/inigral.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/inigral.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/inigral.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/inigral.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/inigral.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/inigral.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/inigral.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/inigral.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/inigral.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/inigral.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/inigral.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/inigral.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/inigral.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/inigral.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=inigral.wordpress.com&amp;blog=4166375&amp;post=25&amp;subd=inigral&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://inigral.wordpress.com/2008/09/05/has_many-through-polymorphic-with-sti/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b9965914922befc565887c3dbb77e03e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Joseph Sofaer</media:title>
		</media:content>
	</item>
		<item>
		<title>Finding the biggest group</title>
		<link>http://inigral.wordpress.com/2008/09/04/finding-the-biggest-group/</link>
		<comments>http://inigral.wordpress.com/2008/09/04/finding-the-biggest-group/#comments</comments>
		<pubDate>Thu, 04 Sep 2008 19:23:46 +0000</pubDate>
		<dc:creator>Michael Sofaer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://inigral.wordpress.com/?p=39</guid>
		<description><![CDATA[An interesting undocumented piece of ActiveRecord I bumped into today is &#8220;count_all&#8221;. You can use this inside ActiveRecord count calls to do sorts and limits based on the count when you&#8217;re doing GROUP BY. I came across this because I was having a bit of trouble recently finding the Rails way to find the biggest [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=inigral.wordpress.com&amp;blog=4166375&amp;post=39&amp;subd=inigral&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>An interesting undocumented piece of ActiveRecord I bumped into today is &#8220;count_all&#8221;.  You can use this inside ActiveRecord count calls to do sorts and limits based on the count when you&#8217;re doing GROUP BY.</p>
<p>I came across this because I was having a bit of trouble recently finding the Rails way to find the biggest student group, and when the most recent joining of that group happened.  What I wanted was a Railsy way to run this query:</p>
<p><code>SELECT member_of_id, count(*) mems, max(created_at) most_recent FROM memberships WHERE member_of_type = 'Organization' GROUP BY member_of_id ORDER BY mems DESC LIMIT 1</code></p>
<p>What this SQL does is return the largest group, the number of members it has, and the time the most recent one was created.  It&#8217;s pretty fast, too.  Now to make it Rails!</p>
<p>ActiveRecord provides us with the powerful count method, which will get us a good portion of the way there, using the group keyword:</p>
<p><code>Membership.count(:group =&gt; "member_of_id", :conditions =&gt; "member_of_type = 'Organization'")</code></p>
<p>This is more Railsy, but it returns a lot of data, and we will need to sort it in memory, and discard the bulk of what we pulled from the database, so it&#8217;s a good deal slower.  What&#8217;s we&#8217;d like to do is sort it in the database, and only return the top row.  It turns out you can do this:</p>
<p><code>largest_organization = Membership.count(:group =&gt; "member_of_id", :conditions =&gt; "member_of_type = 'Organization'", <img src='http://s1.wp.com/wp-includes/images/smilies/icon_surprised.gif' alt=':o' class='wp-smiley' /> rder =&gt; "count_all DESC", :limit =&gt; 1)</code></p>
<p><code>largest_organization_id = largest_organization.first[0] unless largest_organization.blank?</code></p>
<p>This may not be perfectly Rails Way, since I&#8217;m not sure how legit it is to use count_all in the order by clause.  It&#8217;s also not quite as fast as the original SQL, because we still need to run another query to get the most recent join time for the organization:</p>
<p><code>Membership.maximum(:created_at, :conditions =&gt; ["member_of_id = ?", largest_organization_id])</code></p>
<p>Still, it&#8217;s pretty good, and stays inside the standard ActiveRecord paradigm.</p>
<p>Enjoy!</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/inigral.wordpress.com/39/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/inigral.wordpress.com/39/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/inigral.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/inigral.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/inigral.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/inigral.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/inigral.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/inigral.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/inigral.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/inigral.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/inigral.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/inigral.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/inigral.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/inigral.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/inigral.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/inigral.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=inigral.wordpress.com&amp;blog=4166375&amp;post=39&amp;subd=inigral&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://inigral.wordpress.com/2008/09/04/finding-the-biggest-group/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/3991f1dedc443618e34241312283dc60?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mike</media:title>
		</media:content>
	</item>
		<item>
		<title>Reverse SSH Tunneling</title>
		<link>http://inigral.wordpress.com/2008/07/19/reverse-ssh-tunneling/</link>
		<comments>http://inigral.wordpress.com/2008/07/19/reverse-ssh-tunneling/#comments</comments>
		<pubDate>Sat, 19 Jul 2008 22:21:55 +0000</pubDate>
		<dc:creator>Joseph Sofaer</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[facebook platform]]></category>
		<category><![CDATA[reverse ssh tunneling]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://inigral.wordpress.com/?p=5</guid>
		<description><![CDATA[Developing a Facebook Platform application from your local machine (with Ruby on Rails) You have a laptop, a sever and a facebook app. Ideally, Facebook would talk to your development machine &#8211; but what if you don&#8217;t have a static ip address and you can&#8217;t use dynamic dns or port forwarding? Reverse SSH Tunneling is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=inigral.wordpress.com&amp;blog=4166375&amp;post=5&amp;subd=inigral&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h2>Developing a Facebook Platform application from your local machine (with Ruby on Rails)</h2>
<p>You have a laptop, a sever and a facebook app.</p>
<p>Ideally, <strong>Facebook would talk to your development machine</strong> &#8211; but what if you don&#8217;t have a static ip address and you can&#8217;t use dynamic dns or port forwarding?</p>
<p><strong>Reverse SSH Tunneling</strong> is what you need my friend.</p>
<p>The following is a step by step tutorial of what you need to do to have ports on your server forwarded to your local machine via ssh.</p>
<h3>Step 1: Server Side</h3>
<p><strong>Add &#8220;GatewayPorts yes&#8221; into your sshd_config file:</strong></p>
<p><code>sudo nano /etc/ssh/sshd_config</code></p>
<p>&#8211; add or edit the GatewayPorts variable, control-O to save, control-X to exit</p>
<p><strong>Reload ssh:</strong></p>
<p><code>sudo /etc/init.d/ssh reload</code></p>
<h3>Step 2: Your Client</h3>
<p><strong>Run the tunnel:</strong></p>
<p><code>ssh -nNT -g -R 3000:0.0.0.0:3000 me@myserver.com</code></p>
<p>If you want port 1 on your server to go to port 2 on your local it will look like:<br />
ssh -nNT -g -R 1:0.0.0.0:2 you@yourserver.com so you can forward any port on your server to the standard -p 3000 that your rails server is running on.</p>
<h3>Extra-Magic Step: Adding a bit of Rock &amp; Roll</h3>
<p><strong>Add an alias to your ~/bash_profile:</strong></p>
<p><code>alias sshtunnel="ssh -nNT -g -R 3000:0.0.0.0:3000 library@jorgeluisgorgeous.com"</code></p>
<p><strong>Add your public key to the server for password free login</strong></p>
<p>Thanks to Paul McKeller for getting me started on this </p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/inigral.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/inigral.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/inigral.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/inigral.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/inigral.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/inigral.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/inigral.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/inigral.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/inigral.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/inigral.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/inigral.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/inigral.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/inigral.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/inigral.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/inigral.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/inigral.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=inigral.wordpress.com&amp;blog=4166375&amp;post=5&amp;subd=inigral&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://inigral.wordpress.com/2008/07/19/reverse-ssh-tunneling/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/b9965914922befc565887c3dbb77e03e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Joseph Sofaer</media:title>
		</media:content>
	</item>
	</channel>
</rss>
