<?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>P(failure &#124; big_shot_present) = .9 &#187; Rails</title>
	<atom:link href="http://blog.e-thang.net/tag/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.e-thang.net</link>
	<description>If even 1 person reads this, I will consider that a success</description>
	<lastBuildDate>Wed, 19 Oct 2011 14:52:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Deprecation warnings in Rails</title>
		<link>http://blog.e-thang.net/2011/03/22/deprecation-warnings-in-rails/</link>
		<comments>http://blog.e-thang.net/2011/03/22/deprecation-warnings-in-rails/#comments</comments>
		<pubDate>Tue, 22 Mar 2011 12:31:28 +0000</pubDate>
		<dc:creator>e-thang</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.e-thang.net/?p=109</guid>
		<description><![CDATA[Are you working on an ever-evolving code base? Did your project start with an initial engineering effort to fix a specific problem / explore the solution space? As requirements are more fully understood, are you increasingly annoyed with the older code to support different data formats and the like? Do you want to get developers [...]]]></description>
			<content:encoded><![CDATA[<p>Are you working on an ever-evolving code base?  Did your project start with an initial engineering effort to fix a specific problem / explore the solution space?  As requirements are more fully understood, are you increasingly annoyed with the older code to support different data formats and the like?  Do you want to get developers and others to stop using those old formats?</p>
<p>Well, you too can have access to what Rails uses to put deprecation warnings in the log file.</p>
<p><code>ActiveSupport::Deprecation.warn("Stop calling me!")</code></p>
<p>It of course takes a good team policy to require all such warnings to be removed, but I was delighted to find that this is readily available and usable for my own deprecation warnings.  It sure beats using Rails.logger, because the intent is clearer, and such warnings will get shut off when all deprecation warnings are turned off anyway.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.e-thang.net/2011/03/22/deprecation-warnings-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Validation gotcha (before_save not being called)</title>
		<link>http://blog.e-thang.net/2010/10/18/validation-gotcha-before_save-not-being-called/</link>
		<comments>http://blog.e-thang.net/2010/10/18/validation-gotcha-before_save-not-being-called/#comments</comments>
		<pubDate>Mon, 18 Oct 2010 12:51:57 +0000</pubDate>
		<dc:creator>e-thang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[active record]]></category>
		<category><![CDATA[callback]]></category>
		<category><![CDATA[factory girl]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[rails 3]]></category>
		<category><![CDATA[shoulda]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://blog.e-thang.net/?p=105</guid>
		<description><![CDATA[So once I figured it out, there was a generous *facepalm*. Nonetheless, in case you&#8217;re struggling with the same problem, here it goes. I had a before_validation callback on an ActiveRecord model. I was running in test mode using Shoulda and FactoryGirl, so I figured those 2 gems had something to do with it. Then [...]]]></description>
			<content:encoded><![CDATA[<p>So once I figured it out, there was a generous *facepalm*.  Nonetheless, in case you&#8217;re struggling with the same problem, here it goes.</p>
<p>I had a before_validation callback on an ActiveRecord model.  I was running in test mode using Shoulda and FactoryGirl, so I figured those 2 gems had something to do with it.  Then came the humble pie.</p>
<p>I also had a validates_presence_of on the model, and it was getting called before the before_validation callback.  The test wasn&#8217;t setting that attribute, so naturally I never got to the callback.</p>
<p>Once again it was not a cloud if improbability that caused the universe to collapse around me.  It was a bone-headed error.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.e-thang.net/2010/10/18/validation-gotcha-before_save-not-being-called/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Renaming a database in Rails</title>
		<link>http://blog.e-thang.net/2009/12/14/renaming-a-database-in-rails/</link>
		<comments>http://blog.e-thang.net/2009/12/14/renaming-a-database-in-rails/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 17:09:15 +0000</pubDate>
		<dc:creator>e-thang</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[myql]]></category>
		<category><![CDATA[rename database]]></category>

		<guid isPermaLink="false">http://blog.e-thang.net/?p=54</guid>
		<description><![CDATA[Hooray for a non-rant post! The heart of this method works outside of Rails, but there&#8217;s one particular convenience method that Rails provides.  Find some way to mimic that behavior, and the rest would apply.  Also, this is a MySQL-specific solution.  I haven&#8217;t tried it with any other DB systems. We &#8220;rename&#8221; a database by [...]]]></description>
			<content:encoded><![CDATA[<p>Hooray for a non-rant post!</p>
<p>The heart of this method works outside of Rails, but there&#8217;s one particular convenience method that Rails provides.  Find some way to mimic that behavior, and the rest would apply.  Also, this is a MySQL-specific solution.  I haven&#8217;t tried it with any other DB systems.</p>
<p>We &#8220;rename&#8221; a database by moving all of its tables into a new database.  We do so via <a title="MySQL RENAME TABLE Syntax" href="http://dev.mysql.com/doc/refman/5.0/en/rename-table.html">MySQL&#8217;s RENAME TABLE command</a>.  Basically, create an empty database with the new name.  We then use our ActiveRecord connection&#8217;s &#8220;tables&#8221; method to loop over all the tables in our database, executing a RENAME TABLE from the old to the new with each iteration.  &#8220;Tables&#8221; is the convenience method I mentioned above. Encapsulating this in a method we get:</p>
<pre>def rename_database(old_db_name, new_db_name)
    ActiveRecord::Base.connection.execute "CREATE DATABASE #{new_db_name}"
    ActiveRecord::Base.connection.tables.each do |table|
        ActiveRecord::Base.connection.execute
            "RENAME TABLE #{old_db_name}.#{table} TO #{new_db_name}.#{table}"
    end
    ActiveRecord::Base.connection.execute "DROP DATABASE #{old_db_name}"
end</pre>
<p>Error checking is left as an (important!) exercise to the reader.  Also, you may prefer to monkey patch this into ActiveRecord itself as opposed to some odd method floating around in global space.</p>
<p>This presupposes that the new database destination will be on the same server.</p>
<p>Another way to rename a database is to mysqldump the old one to a file and then reimport it to the renamed database.  The method presented in this article is advantageous if your database has a large amount of data.  Renaming a table is almost instant.  <strong>Dumping millions of rows and reimporting them is not so instant.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.e-thang.net/2009/12/14/renaming-a-database-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>uninitialized constant Thin::Server::Forwardable</title>
		<link>http://blog.e-thang.net/2009/07/02/uninitialized-constant-thinserverforwardable/</link>
		<comments>http://blog.e-thang.net/2009/07/02/uninitialized-constant-thinserverforwardable/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 21:30:41 +0000</pubDate>
		<dc:creator>e-thang</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[forwardable]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[thin]]></category>
		<category><![CDATA[weird]]></category>

		<guid isPermaLink="false">http://blog.e-thang.net/?p=42</guid>
		<description><![CDATA[I may be getting batty in my old age here, but for whatever reason Thin decided to just stop running on my system.  When trying to invoke thin to further development on the code behind my awesome website, I was treated to the following: ethan:ethang juanpaco$ thin start /Library/Ruby/Gems/1.8/gems/thin-1.0.0/lib/thin/server.rb:51: uninitialized constant Thin::Server::Forwardable (NameError) from /Library/Ruby/Gems/1.8/gems/thin-1.0.0/lib/thin/runner.rb:38:in [...]]]></description>
			<content:encoded><![CDATA[<p>I may be getting batty in my old age here, but for whatever reason Thin decided to just stop running on my system.  When trying to invoke thin to further development on <a href="http://github.com/juanpaco/e-thang.net/tree/master">the code</a> behind <a href="http://www.e-thang.net">my awesome website</a>, I was treated to the following:</p>
<p><code><br />
ethan:ethang juanpaco$ thin start<br />
/Library/Ruby/Gems/1.8/gems/thin-1.0.0/lib/thin/server.rb:51: uninitialized constant Thin::Server::Forwardable (NameError)<br />
from /Library/Ruby/Gems/1.8/gems/thin-1.0.0/lib/thin/runner.rb:38:in `initialize'<br />
from /Library/Ruby/Gems/1.8/gems/thin-1.0.0/bin/thin:6:in `new'<br />
from /Library/Ruby/Gems/1.8/gems/thin-1.0.0/bin/thin:6<br />
from /usr/bin/thin:19:in `load'<br />
from /usr/bin/thin:19</code></p>
<p>I didn&#8217;t like that.</p>
<p>I went to the line number where the error occurred (/Library/Ruby/Gems/1.8/gems/thin-1.0.0/lib/thin/server.rb:51), and found:<br />
<code>extend  Forwardable</code></p>
<p>Not knowing what Forwardable was, and for giggles, I went to irb and typed &#8220;Forwardable&#8221; thinking I&#8217;d get the class object.  Not defined.  So I try &#8220;require &#8216;forwardable&#8217;.&#8221;  There was no period in what I typed, but I haven&#8217;t figured out how to get Ruby and English to play well together.  Anyway, that worked, and a subsequent typing of &#8220;Forwardable&#8221; returned the object. So then I tried putting require &#8216;forwardable&#8217; at the top of server.rb in thin&#8217;s gem.</p>
<p>And then it worked.</p>
<p>I&#8217;m not sure why it used to work and then suddenly didn&#8217;t.  This was after several install/uninstall, swear off programming moments.  Weird.  So, if you&#8217;re struggling with this same problem, perhaps the above can be of service.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.e-thang.net/2009/07/02/uninitialized-constant-thinserverforwardable/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Debuggin&#8217; in Rails</title>
		<link>http://blog.e-thang.net/2008/12/26/debuggin-in-rails/</link>
		<comments>http://blog.e-thang.net/2008/12/26/debuggin-in-rails/#comments</comments>
		<pubDate>Fri, 26 Dec 2008 16:04:38 +0000</pubDate>
		<dc:creator>e-thang</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[ruby-debug]]></category>

		<guid isPermaLink="false">http://blog.e-thang.net/?p=36</guid>
		<description><![CDATA[This is a for-my-benefit-reference post like the last 2.  Perhaps I&#8217;ll do a better write-up of ruby-debug at a later time. &#8220;info breakpoints&#8221; to see the list of set breakpoints.]]></description>
			<content:encoded><![CDATA[<p>This is a for-my-benefit-reference post like the last 2.  Perhaps I&#8217;ll do a better write-up of ruby-debug at a later time.</p>
<p>&#8220;info breakpoints&#8221; to see the list of set breakpoints.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.e-thang.net/2008/12/26/debuggin-in-rails/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Production mode cluster conundrum</title>
		<link>http://blog.e-thang.net/2008/07/16/production-mode-cluster-conundrum/</link>
		<comments>http://blog.e-thang.net/2008/07/16/production-mode-cluster-conundrum/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 16:08:38 +0000</pubDate>
		<dc:creator>e-thang</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[dark_wizard]]></category>
		<category><![CDATA[helper]]></category>

		<guid isPermaLink="false">http://blog.e-thang.net/?p=16</guid>
		<description><![CDATA[I wish I had some cool screenshots for this one, but hopefully a text-based description will suffice. So I fixed a bug at work, where certain AJAX calls were failing.  It turns out that our view templates were making some assumptions that they ought not to have been making.  I fixed that error, and our [...]]]></description>
			<content:encoded><![CDATA[<p>I wish I had some cool screenshots for this one, but hopefully a text-based description will suffice.</p>
<p>So I fixed a bug at work, where certain AJAX calls were failing.  It turns out that our view templates were making some assumptions that they ought not to have been making.  I fixed that error, and our QA team pushed that code out to our test servers (along with other things&#8211; I wasn&#8217;t that important).  Well, the error, or at least its symptoms, showed up again.  Now, it only showed up sometimes, and only on the test server.  &#8220;It works on my machine,&#8221; not being much of a solution to a bug, I started investigating.</p>
<p>I looked into the error logs that were being generated, and saw what looked like the sort of error you get when you call a helper method which doesn&#8217;t exist.  As part of the bug fix, I added a helper method.  We checked manually the code that was running on the server, and it had the helper method and the full new version of the code.  At this point I began suspecting the work of some foul dark wizard&#8211; or at least a gremlin.  I mean, why else would a view template not be able to find a helper method that is there after the server has been restarted?</p>
<p>I&#8217;ll tell you why.  We have a cluster configuration, and Capistrano or something else, hadn&#8217;t shut down every process running the old code.  Since AJAX calls are full-blown server requests that just happen not to refresh the whole browser page, some of those calls were directed to server processes that hadn&#8217;t actually been restarted.  Rails doesn&#8217;t auto-refresh code in production mode (Good Thing), so those old processes quite naturally didn&#8217;t find the new code.  We killed the old processes and, presto!  The world is right again.</p>
<p>So, if you ever find yourself wondering why your view template can&#8217;t find your helper method, check to make sure that your server restart restarted ALL instances of your application. We&#8217;re still not entirely sure why all instances didn&#8217;t restart though.</p>
<p>So, Dark Wizards may still be involved.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.e-thang.net/2008/07/16/production-mode-cluster-conundrum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

