<?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>game, game. repeat. &#187; ruby</title>
	<atom:link href="http://ggr.com/tag/ruby/feed" rel="self" type="application/rss+xml" />
	<link>http://ggr.com</link>
	<description>if Scott Bonds had a home on the interwebs, this would be it</description>
	<lastBuildDate>Tue, 07 Feb 2012 00:11:34 +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>How to Restart PostgreSQL While Developing a Rails App</title>
		<link>http://ggr.com/how-to-restart-postgresql-while-developing-a-rails-app.html</link>
		<comments>http://ggr.com/how-to-restart-postgresql-while-developing-a-rails-app.html#comments</comments>
		<pubDate>Fri, 13 Jan 2012 19:24:14 +0000</pubDate>
		<dc:creator>Scott Bonds</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[connections]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[postgres]]></category>
		<category><![CDATA[postgresql]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://ggr.com/?p=484</guid>
		<description><![CDATA[While developing a Rails apps using PostgreSQL (unlike MySQL) I often run out of db connections and see errors like &#8220;FATAL:  remaining connection slots are reserved for non-replication superuser connections&#8221; and when I do, my Rails app stops working. Restarting Postgres fixing the problem, but it was harder to restart postgres that I expected. Here&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://ggr.com/how-to-restart-postgresql-while-developing-a-rails-app.html"><img class="aligncenter size-full wp-image-486" title="ran out of connections" src="http://ggr.com/wp-content/uploads/ran-out-of-connections.jpg" alt="" width="580" height="198" /></a></p>
<p>While developing a Rails apps using PostgreSQL (unlike MySQL) I often run out of db connections and see errors like &#8220;FATAL:  remaining connection slots are reserved for non-replication superuser connections&#8221; and when I do, my Rails app stops working. Restarting Postgres fixing the problem, but it was harder to restart postgres that I expected. Here&#8217;s how I do it.<span id="more-484"></span></p>
<p>To restart PostgreSQL I added a function to my ~/.bash_profile file:</p>
<pre class="wp-code-highlight prettyprint"># restart postgres
pgr() {
  kill `ps -ef | grep postgres | grep -v grep | awk '{print $2}'`
}</pre>
<p>After saving and restarting Terminal, running &#8216;pgr&#8217; will find all the postgres process and kill them. Once launchd notices postgres is down it restarts it because I setup launchd to keep postgres running no matter what. If you don&#8217;t have postgres setup to stay running, you would need to start postgres whatever way matches your setup.</p>
<p>I tried a number of different solutions before I arrived at this one:</p>
<ol>
<li>running &#8216;pg_ctl -D &lt;path to db&gt; restart&#8217; would cause postgres to try and restart, but it would timeout unsuccessful</li>
<li>logging out then logging back in again works (since I&#8217;m running postgres as a &#8216;personal&#8217; launch agent, it starts and stops with my login and logout) but that&#8217;s terribly disruptive to my work</li>
<li>killall would kill some, but not all of the errant postgres processes</li>
</ol>
<p>I&#8217;m running OSX Lion, PostgreSQL 9.1.2, Rails 3.1.3, Ruby 1.9.2-p290.</p>
<p>I Googled the hive-mind for a better answer, after all, when developing a rails app using MySQL I had no such problem. It seems others have run into this, but I didn&#8217;t find a better solution. I have a nagging feeling there&#8217;s some setting I could add to my database.yml file to get PostgreSQL to behave well in my development environment and obviate the need for my PostgreSQL restarting shenanigans, but I&#8217;ve not yet discovered it.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://ggr.com/how-to-restart-postgresql-while-developing-a-rails-app.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How To Use Facebook Open Streams With Facebooker</title>
		<link>http://ggr.com/how-to-use-facebook-open-streams-with-facebooker.html</link>
		<comments>http://ggr.com/how-to-use-facebook-open-streams-with-facebooker.html#comments</comments>
		<pubDate>Tue, 15 Sep 2009 22:02:40 +0000</pubDate>
		<dc:creator>Scott Bonds</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[authlogic]]></category>
		<category><![CDATA[authlogic facebook connect plugin]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[facebook connect]]></category>
		<category><![CDATA[facebooker]]></category>
		<category><![CDATA[news feed]]></category>
		<category><![CDATA[open streams api]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[stream]]></category>
		<category><![CDATA[stream.publish]]></category>

		<guid isPermaLink="false">http://ggr.com/?p=395</guid>
		<description><![CDATA[I would like my Facebook Connect app to publish stories to my users&#8217; Facebook news stream. I went looking for how do this with Facebooker and figured out an answer. The old way of doing this, and the one built into Facebooker, is to publish a user action. There are two limitations of the old [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://ggr.com/how-to-use-facebook-open-streams-with-facebooker.html"><img class="size-full wp-image-399 aligncenter" title="facebook_extended_permissions" src="http://ggr.com/wp-content/uploads/facebook_extended_permissions.jpg" alt="facebook_extended_permissions" width="580" height="287" /></a></p>
<p>I would like my Facebook Connect app to publish stories to my users&#8217; Facebook news stream.  I went looking for how do this with Facebooker and figured out an answer.</p>
<p><span id="more-395"></span></p>
<p>The <a href="http://wiki.developers.facebook.com/index.php/Feed.publishUserAction">old way</a> of doing this, and the one built into Facebooker, is to <a href="http://facebooker.rubyforge.org/classes/Facebooker/Rails/Publisher.html">publish a user action</a>.  There are two limitations of the old way: 1: you need a valid session_key (so, the user must be logged in); 2: you may only send up to 10 messages per day (without special permissions from the user).</p>
<p>Fortunately Facebook released their <a href="http://wiki.developers.facebook.com/index.php/Using_the_Open_Stream_API">Open Stream API</a> in April 2009 and it suffers from neither restriction: you can post without a session_key and there are no explicit limits on how many posts you can make in a day.  Unfortunately Facebooker does not yet offer native support for publishing to Facebook streams, at least that I could find, but it DOES support rolling your own API calls, and in this case its not that hard to do.  To post to a users&#8217; Facebook stream from your Rails app&#8217;s script/console, do the following:</p>
<ol>
<li>Integrate Facebooker into your Rails app.  Verify that it works.  There are a number of ways to integrate Facebooker depending on what kind of app you are making.  e.g. I&#8217;m making a Facebook Connect app, so I used <a href="http://github.com/binarylogic/authlogic">AuthLogic</a> and the <a href="http://github.com/kalasjocke/authlogic_facebook_connect">AuthLogic Facebook Connect plugin</a> so users can login to my app using their Facebook credentials.</li>
<li>Get a user&#8217;s <a href="http://wiki.developers.facebook.com/index.php/Extended_permission">permission to publish</a> to their stream.  Make a note of their Facebook UID.  e.g. in my app, the AuthLogic Facebook Connect plugin stores the UID in my user table each time a new Facebook user logs into my site.</li>
<li>Run script/console and execute the following commands:</li>
</ol>
<p><code><strong> f = Facebooker::Session.create<br />
f.post 'facebook.stream.publish', :uid =&gt; '&lt;insert_facebook_uid_here&gt;', :message =&gt; 'test'<br />
</strong> </code></p>
<p>Not so bad, huh?</p>
]]></content:encoded>
			<wfw:commentRss>http://ggr.com/how-to-use-facebook-open-streams-with-facebooker.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How To Include a Gem&#8217;s Rake Tasks in Your Rails App</title>
		<link>http://ggr.com/how-to-include-a-gems-rake-tasks-in-your-rails-app.html</link>
		<comments>http://ggr.com/how-to-include-a-gems-rake-tasks-in-your-rails-app.html#comments</comments>
		<pubDate>Mon, 14 Sep 2009 19:21:32 +0000</pubDate>
		<dc:creator>Scott Bonds</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[facebooker]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[rake tasks]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby gem]]></category>

		<guid isPermaLink="false">http://ggr.com/?p=387</guid>
		<description><![CDATA[Rake tasks contained in a gem are not automatically available to a rails app that requires the gem. Whether that&#8217;s the right way to do things is under debate, but in the mean time there are a couple workarounds. Option #1: Use the gem as a plugin instead. Files that match the following pattern are [...]]]></description>
			<content:encoded><![CDATA[<p>Rake tasks contained in a gem are not automatically available to a rails app that requires the gem.  Whether that&#8217;s the right way to do things is <a href="https://rails.lighthouseapp.com/projects/8994/tickets/59">under debate</a>, but in the mean time there are a couple workarounds.</p>
<p><span id="more-387"></span></p>
<p><strong>Option #1</strong>: Use the gem as a plugin instead.  Files that match the following pattern are automatically pulled in, so you&#8217;re good to go:</p>
<p><code>"#{RAILS_ROOT}/vendor/plugins/*/**/tasks/**/*.rake"</code></p>
<p><strong>Option #2</strong>: Create a ruby file that loads the gem&#8217;s tasks, then require the ruby file you made in your rail app&#8217;s Rakefile.  For example, if you&#8217;ve installed the Facebooker gem and you want to use its rake tasks, you might create a file called &#8216;facebooker.rb&#8217; and save it to your <em>&lt;railsapproot&gt;/tasks</em> directory with these contents:</p>
<p><code>$VERBOSE = nil<br />
Dir["#{Gem.searcher.find('facebooker').full_gem_path}/lib/tasks/*.rake"].each { |ext| load ext }</code></p>
<p>Then add this line to your Rakefile:</p>
<p><code>require 'tasks/facebooker'</code></p>
<p>But as it turns out, Facebooker&#8217;s tasks uses relative paths to get at its config file in your rails app, which won&#8217;t work if its installed in the gem path as a gem rather than in your rails app as a plugin!  So be careful with using option #2, it may not be what the gem you&#8217;re trying to use expects.</p>
]]></content:encoded>
			<wfw:commentRss>http://ggr.com/how-to-include-a-gems-rake-tasks-in-your-rails-app.html/feed</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How To Permit A Blank Email Field With AuthLogic</title>
		<link>http://ggr.com/how-to-permit-a-blank-email-field-with-authlogic.html</link>
		<comments>http://ggr.com/how-to-permit-a-blank-email-field-with-authlogic.html#comments</comments>
		<pubDate>Wed, 09 Sep 2009 19:32:12 +0000</pubDate>
		<dc:creator>Scott Bonds</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[authlogic]]></category>
		<category><![CDATA[blank email]]></category>
		<category><![CDATA[empty email]]></category>
		<category><![CDATA[no email]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://ggr.com/?p=380</guid>
		<description><![CDATA[I too ran into some trouble before discovering that my beloved AuthLogic is validating my email field. The validation is a good thing overall, but I want to support blank email addresses as well as properly formatted ones. It&#8217;s all in the AuthLogic docs of course, but if I can save you a few minutes [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://ggr.com/how-to-permit-a-blank-email-field-with-authlogic.html"><img class="size-full wp-image-381 aligncenter" title="errors from blank email with AuthLogic" src="http://ggr.com/wp-content/uploads/errors-from-blank-email-with-AuthLogic.jpg" alt="errors from blank email with AuthLogic" width="580" height="282" /></a></p>
<p>I too <a href="http://ficial.wordpress.com/2009/03/15/ruby-on-rails-getting-error-messages-authlogic-email-validation/">ran into some trouble</a> before discovering that my beloved AuthLogic is validating my email field.  The validation is a good thing overall, but I want to support blank email addresses as well as properly formatted ones.</p>
<p><span id="more-380"></span></p>
<p>It&#8217;s all in the AuthLogic docs of course, but if I can save you a few minutes of hunting around, that&#8217;s all good:</p>
<p><code><br />
acts_as_authentic do |c|<br />
&nbsp;&nbsp;c.merge_validates_length_of_email_field_options({:allow_nil =&gt; true})<br />
&nbsp;&nbsp;c.merge_validates_format_of_email_field_options({:allow_nil =&gt; true})<br />
end<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://ggr.com/how-to-permit-a-blank-email-field-with-authlogic.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

