<?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>Embracing Chaos &#187; Ruby on Rails</title>
	<atom:link href="http://www.embracingchaos.com/ruby-on-rails/feed" rel="self" type="application/rss+xml" />
	<link>http://www.embracingchaos.com</link>
	<description>Leo Parker Dirac on Business and Technology Trends</description>
	<lastBuildDate>Wed, 14 Jul 2010 01:21:03 +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>Choosing a web framework: Python, Django vs. Ruby on Rails</title>
		<link>http://www.embracingchaos.com/2010/05/choosing-a-web-framework-python-django-vs-ruby-on-rails.html</link>
		<comments>http://www.embracingchaos.com/2010/05/choosing-a-web-framework-python-django-vs-ruby-on-rails.html#comments</comments>
		<pubDate>Mon, 24 May 2010 02:20:31 +0000</pubDate>
		<dc:creator>leodirac</dc:creator>
				<category><![CDATA[Geek]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://www.embracingchaos.com/?p=1027</guid>
		<description><![CDATA[One of my responsibilities in my new job is to lay the groundwork for development of the company&#8217;s technology.  One decision that was pretty easy to make is that we&#8217;ll be building tools that you can use from a web browser, that is to say, a web application.  Next comes the choice of what language [...]]]></description>
			<content:encoded><![CDATA[<p>One of my responsibilities in my <a href="http://www.embracingchaos.com/2010/05/how-social-media-will-change-marketing.html">new job</a> is to lay the groundwork for development of the company&#8217;s technology.  One decision that was pretty easy to make is that we&#8217;ll be building tools that you can use from a web browser, that is to say, a web application.  Next comes the choice of <strong>what language and framework to build the web application in.</strong></p>
<p>Having been writing code for 25+ years, the differences between programming languages fade away in my mind.  I know that I, like any good software engineer, can be productive in basically any language.  Certainly within object-oriented languages, (which is where essentially all serious software engineering happens these days) the differences in the language itself are IMHO small compared with other factors in choosing a platform.  Other <strong>important factors</strong> I consider include:</p>
<ul>
<li>Quality and availability of <strong>libraries.</strong></li>
<li>Quality of <strong>tools</strong> like IDEs, debuggers, automation systems.</li>
<li>Size and healthy of the active <strong>community</strong> using the framework.  (i.e. If I run into a problem, how easy is it to google the answer?)</li>
<li>Ease of <strong>hiring</strong> people who already know the platform.</li>
</ul>
<p>All of these considerations are IMHO more important than compiled vs. interpreted or run-time performance or whether the language is statically typed or dynamically typed, or even if it&#8217;s open source vs. proprietary technology.  But there is a single common factor which directly feeds into all four of the criteria I list above: <strong>How many people are actively using the platform?</strong></p>
<h4>The Candidates</h4>
<p>The last time I was really writing much code was back in 2007.  At the time <a href="http://rubyonrails.org/">Ruby on Rails</a> was the coolest thing since sliced bread.  I played around with it, was amazed by how easy it was to quickly put together simple database-driven websites, and got very frustrated with it when I wanted to color outside of its lines.  A major concern of mine was <strong>the level of &#8220;magic&#8221; that happens behind the scenes</strong> &#8212; this <strong>makes Rails beautiful and elegant when it works, but difficult to debug or extend</strong>.  I blogged about <a href="http://www.embracingchaos.com/ruby-on-rails">my experiences with rails</a> and in particular my conclusion that at the time <a href="http://www.embracingchaos.com/2007/03/scaling_ruby_to.html">Rails was not ready for large, complex projects</a>, partly because of a lack of good tools, libraries and sensible error messages, all of which can be fixed by more users.</p>
<p>Around then I <a href="http://www.embracingchaos.com/2007/10/im-working-for.html">started working for Google</a> and stopped writing code.  The next year or so saw a couple big things happen for Ruby on Rails.  Twitter <a href="http://techcrunch.com/2007/12/20/twitter-downtime-on-the-upswing/">famously</a> had <a href="http://techcrunch.com/2008/06/06/twitter-suffers-minor-period-of-uptime-overnight/">trouble</a> maintaining even 99% uptime (fail whale anybody?), and everybody knew they were running on Ruby on Rails.  Also, Google launched AppEngine, which supported Python, not Ruby, and pointed people like me to an alternative high-level web framework: <a href="http://www.djangoproject.com/">Django</a>.</p>
<p>So now, in 2010, I return to the fray, and I&#8217;m trying to decide between the two frameworks.  There are of course other alternatives, but for the purpose of brevity, I&#8217;ll leave out my process of reducing my choices to these two: <strong>django or rails</strong>?</p>
<h4>Measuring community activity</h4>
<p>I often use <a href="http://www.google.com/trends"><strong>Google Trends</strong></a><strong> to measure relative interest in technologies</strong>.  My time is very valuable, so even downloading something and reading its documentation is an investment I&#8217;d rather shortcut if I can.  This crude measure of relative search activity can actually be quite telling, and has saved me a bunch of time in choosing packages.</p>
<p><a rel="attachment wp-att-1030" href="http://www.embracingchaos.com/2010/05/choosing-a-web-framework-python-django-vs-ruby-on-rails.html/screen-shot-2010-05-23-at-6-40-28-pm"><img class="alignnone size-full wp-image-1030" title="Rails vs Django" src="http://www.embracingchaos.com/wp-content/uploads/2010/05/Screen-shot-2010-05-23-at-6.40.28-PM.png" alt="" width="596" height="307" /></a></p>
<p>The relative values are hard to take literally since &#8220;django&#8221; as a single word search query will naturally be higher than a 3-word query like &#8220;ruby on rails&#8221;, but the search for &#8220;rails&#8221; by itself will clearly have lots of irrelevant searches.  Likewise, some people searching for &#8220;Django&#8221; won&#8217;t be looking for the web framework, but rather the <a href="http://en.wikipedia.org/wiki/Django_Reinhardt">guitarist</a> or the <a href="http://www.imdb.com/title/tt0060315/">movie</a> or what-have you.</p>
<p>But it is clear that <strong>search activity for Ruby on Rails peaked in 2007-2008 and has been declining since then, while Django has been on a steady upwards trend</strong>.</p>
<p>Elsewhere I can find evidence that Rails is still a more used platform.  <a href="http://stackoverflow.com/"><strong>Stackoverflow</strong></a> has twice as many questions about Ruby on Rails vs Django: 13,882 versus 7,496.  To me this <strong>indicates pretty clearly that Rails is more active than Django</strong>.  Either that or Rails is more confusing and people ask more questions about it, but I doubt that.</p>
<p>The <a href="http://www.tiobe.com/index.php/tiobe_index">Tiobe Index</a> attempts to objectively measure activity across programming languages.  By its <a href="http://blog.timbunce.org/2009/05/17/tiobe-index-is-being-gamed/">easily manipulated</a> measure, <a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html">Python has twice the activity of Ruby</a>, independent of the django / rails frameworks, with both languages in decline.</p>
<p>Meanwhile it&#8217;s easy to find comparisons on the net between the two.  Everything from <a href="http://www.youtube.com/watch?v=PLUS00QrYWw">content-free videos</a> to people <a href="http://www.crazyontap.com/topic.php?TopicId=71351&amp;Posts=29">declaring rails dead</a>, and <a href="http://rubyonrailsdevelopment.pl/ruby-on-rails-developers/rails-web-2-0">everything</a> <a href="http://mackstar.com/blog/2010/04/23/django-vs-rails">in</a> <a href="http://www.ctctlabs.com/index.php/blog/detail/rails_vs_django/">between</a>.</p>
<p>On balance, I find the stackoverflow numbers the most compelling, unbiased indication that <strong>Ruby on Rails has more activity than Django / Python</strong>.  Even though I&#8217;ve been frustrated by it in the past, by my own objective criteria, that seems to make <strong>Rails a better choice for building a new web application</strong>.</p>
<h4>What&#8217;s your opinion?</h4>
<p>If you have experience with both frameworks, I&#8217;d love to hear your experiences.  Please leave a comment.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.embracingchaos.com/2010/05/choosing-a-web-framework-python-django-vs-ruby-on-rails.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Tagmindr: Use del.icio.us to set web-page reminders</title>
		<link>http://www.embracingchaos.com/2007/10/tagmindr-use-de.html</link>
		<comments>http://www.embracingchaos.com/2007/10/tagmindr-use-de.html#comments</comments>
		<pubDate>Mon, 08 Oct 2007 07:55:44 +0000</pubDate>
		<dc:creator>leodirac</dc:creator>
				<category><![CDATA[Ego]]></category>
		<category><![CDATA[Geek]]></category>
		<category><![CDATA[Infoglut]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Seattle]]></category>

		<guid isPermaLink="false">http://wp.embracingchaos.com/2007/10/tagmindr-use-de.html</guid>
		<description><![CDATA[I spent Saturday hanging out with about a dozen hackers building Tagmindr: Remember the future. Here's the site's self-description: Put any bookmark in a time capsule and we'll send it to your future self. Give us your del.icio.us username and we'll feed you anything that you've tagged as: "tagmindr" and "remind:YYYY-MM-DD". We'll remind you via RSS, SMS, Email or IM, so long as it's RSS. (SMS, Email and IM coming later.) The use case is that you find a page about a product or service that you'd like to look at sometime later so you tag it into del.icio.us thinking...
]]></description>
			<content:encoded><![CDATA[<div style="overflow: hidden; width: 260px; float: right;"><a href="http://www.tagmindr.com/"><img src="http://www.tagmindr.com/img/ui-logo.jpg" style="border: 0pt none ; width: 400px;" /></a></div>
<p>I spent Saturday hanging out with about a dozen hackers building <a href="http://www.tagmindr.com/">Tagmindr: Remember the future</a>.&nbsp; Here&#8217;s the site&#8217;s self-description:</p>
<ul>
<p>Put any bookmark in a time capsule and we&#8217;ll send it to your future self.</p>
<p>
Give us your del.icio.us username and we&#8217;ll feed you anything that you&#8217;ve tagged as: &quot;tagmindr&quot; and &quot;remind:YYYY-MM-DD&quot;. We&#8217;ll remind you via RSS, SMS, Email or IM, so long as it&#8217;s RSS.</p>
<p>
(SMS, Email and IM coming later.)</p>
</ul>
<p>The use case is that you find a page about a product or service that you&#8217;d like to look at sometime later so you tag it into <a href="http://del.icio.us">del.icio.us</a> thinking you&#8217;ll get back to it, but of course you never will.&nbsp; With Tagmindr you can set a specific date when it will pop up in your feed reader so you will remember to check it out again.</p>
<p><a href="http://briandorsey.info/">Brian Dorsey</a> came up with the idea and gathered a bunch of us together at his house with the goal of building a web 2.0 app in 6 hours.&nbsp; We spent an hour or two setting up our dev environments and talking over the goals of what we were going to do.&nbsp; Then we did a skills inventory, and divided up into teams to start doing the work.&nbsp; I worked on the back-end team which was a ton of fun.&nbsp; The project is written using Django, an MVC-based web application framework for Python, which is conceptually quite similar to Rails.&nbsp; It&#8217;s got a few things that are way cooler than rails and a few things that are definitely lacking.&nbsp; From noon to 6pm we coded, while others did graphic design, HTML layout, and wrote copy.&nbsp; I had to leave fairly promptly but at the time it seemed we had slipped just a bit &#8212; there were still a few issues rendering the design on the production server, and the back-end code still had a couple of bugs.&nbsp; It seemed like another hour or two&#8217;s work total.</p>
<p>Thanks and props to all the wonderful people I met and got to work with.&nbsp; Special thanks to <a href="http://anders.conbere.org/">Anders</a> for holding my hand through basic Python and Django to a level of minor productivity.&nbsp; I gotta say that Python is really clean.&nbsp; Makes me realize how much Ruby can look like incomprehensible Perl.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.embracingchaos.com/2007/10/tagmindr-use-de.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Rails bug with assert_redirected_to causing NoMethodError: undefined method `first&#8217;</title>
		<link>http://www.embracingchaos.com/2007/10/assert_redirect.html</link>
		<comments>http://www.embracingchaos.com/2007/10/assert_redirect.html#comments</comments>
		<pubDate>Sun, 07 Oct 2007 15:54:00 +0000</pubDate>
		<dc:creator>leodirac</dc:creator>
				<category><![CDATA[Geek]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://wp.embracingchaos.com/2007/10/assert_redirect.html</guid>
		<description><![CDATA[I'm posting about a bug I ran into recently in Rails. It's filed against the core team and being addressed, and documented on the forums, so this post might be unnecessary. But the bug is bizarre and confusing enough that I thought I'd post a succinct summary of the problem and how to fix it. If you have code in a controller that redirects to another page, say like this: def index redirect_to :controller => :store # WRONG! end This looks fine and actually runs fine too. But there's a problem if you try to test it -- the tests...
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m posting about a bug I ran into recently in Rails.&nbsp; It&#8217;s <a href="http://dev.rubyonrails.org/ticket/9525">filed</a> against the core team and being addressed, and <a href="http://railsforum.com/viewtopic.php?pid=40532">documented on the forums</a>, so this post might be unnecessary.&nbsp; But the bug is bizarre and confusing enough that I thought I&#8217;d post a succinct summary of the problem and how to fix it.</p>
<p>If you have code in a controller that redirects to another page, say like this:</p>
<pre>&nbsp; def index&nbsp; &nbsp; redirect_to :controller =&gt; :store&nbsp; # WRONG!&nbsp; end</pre>
<p>This looks fine and actually runs fine too.&nbsp; But there&#8217;s a problem if you try to test it &#8212; the tests will fail.&nbsp; Consider this simple test case:</p>
<pre>&nbsp; def test_index&nbsp; &nbsp; get :index&nbsp; &nbsp; assert_response :redirect&nbsp; &nbsp; assert_redirected_to :controller =&gt; 'store'&nbsp; end</pre>
<p>This test will fail with this unhelpful error message:</p>
<pre>&nbsp; 1) Error:test_index(WidgetsControllerTest):NoMethodError: undefined method `first' for :store:Symbol&nbsp; &nbsp; /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/assertions/response_assertions.rb:72:in `assert_redirected_to'&nbsp; &nbsp; /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/assertions/response_assertions.rb:43:in `each'&nbsp; &nbsp; /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/assertions/response_assertions.rb:43:in `assert_redirected_to'&nbsp; &nbsp; /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/assertions.rb:60:in `clean_backtrace'&nbsp; &nbsp; /usr/local/lib/ruby/gems/1.8/gems/actionpack-1.13.3/lib/action_controller/assertions/response_assertions.rb:35:in `assert_redirected_to'&nbsp; &nbsp; ./test/functional/widgets_controller_test.rb:21:in `test_index'</pre>
<p>The problem is in that controller code.&nbsp; Apparently (this was news to me) Ruby strings and symbols aren&#8217;t the same.&nbsp; That is :store and &#8217;store&#8217; compile to different code.&nbsp; If you change your controller to this:</p>
<pre>&nbsp; def index&nbsp; &nbsp; # redirect_to :controller =&gt; :store&nbsp; # WRONG!
&nbsp; &nbsp; redirect_to :controller =&gt; 'store'&nbsp; &nbsp;# Correct
&nbsp; end</pre>
<p>Not only will the code function properly, but it will pass the functional test too.&nbsp; Hope this helps.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.embracingchaos.com/2007/10/assert_redirect.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Facebook apps in Rails: Bug in rfacebook-0.6.4 &#8211; fbparams not set</title>
		<link>http://www.embracingchaos.com/2007/07/facebook-apps-i.html</link>
		<comments>http://www.embracingchaos.com/2007/07/facebook-apps-i.html#comments</comments>
		<pubDate>Sat, 21 Jul 2007 04:14:02 +0000</pubDate>
		<dc:creator>leodirac</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://wp.embracingchaos.com/2007/07/facebook-apps-i.html</guid>
		<description><![CDATA[Like a number of other developers, I've been beating my head against a wall for the last couple of weeks trying to figure out how to set up a facebook app using ruby on rails. I finally figured out at least one major problem I've been running into -- the standard library for writing facebook apps in ruby, rfacebook, has a bug in its latest version 0.6.4. I haven't figured out exactly what's wrong yet, but I've figured out how to avoid it. If you're getting this kind of error message: You have a nil object when you didn't expect...
]]></description>
			<content:encoded><![CDATA[<p><img width="200" src="http://saltwatercoffee.com/wp-content/uploads/2006/08/computer_repair_large.jpg" class="top" /><a href="http://facebook.jdg.net/posts/search?q=activate">Like a number of other developers</a>, I&#8217;ve been beating my head against a wall for the last couple of weeks trying to figure out how to set up a facebook app using ruby on rails.&nbsp; I finally figured out at least one major problem I&#8217;ve been running into &#8212; the standard library for writing facebook apps in ruby, <strong>rfacebook, has a bug in its latest version 0.6.4</strong>.</p>
<p>I haven&#8217;t figured out exactly what&#8217;s wrong yet, but I&#8217;ve figured out how to avoid it.&nbsp; If you&#8217;re getting this kind of error message:</p>
<pre>You have a nil object when you didn't expect it!You might have expected an instance of Array.The error occurred while evaluating nil.length</pre>
<p>The error might comes from a stack trace like this:</p>
<pre>.../rfacebook-0.6.4/lib/facebook_rails_controller_extensions.rb:37:in `fbparams'
.../rfacebook-0.6.4/lib/facebook_rails_controller_extensions.rb:60:in `fbsession'
.../rfacebook-0.6.4/lib/facebook_rails_controller_extensions.rb:130:in `require_facebook_login'
</pre>
<p>
Astute developers will open up the code and see that fbparams isn&#8217;t being properly initialized because of a simple blunder &#8212; calling a method on a potentially nil object before trying to initialize it.&nbsp; But correcting this mistake won&#8217;t get your app to run.&nbsp; There are other problems too.&nbsp; <strong>The way to fix your app is to back down to rfacebook version 0.6.3:</strong></p>
<p><code><strong>gem uninstall rfacebook<br />gem install rfacebook -v 0.6.3</strong></code></p>
<p>And don&#8217;t forget to clear your cookies and your session objects</p>
<p><code>rm tmp/sessions/*</code></p>
<p>This has certainly helped me.&nbsp; I hope it helps you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.embracingchaos.com/2007/07/facebook-apps-i.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Model Security: Such a good idea</title>
		<link>http://www.embracingchaos.com/2007/05/model_security_.html</link>
		<comments>http://www.embracingchaos.com/2007/05/model_security_.html#comments</comments>
		<pubDate>Thu, 10 May 2007 01:54:00 +0000</pubDate>
		<dc:creator>leodirac</dc:creator>
				<category><![CDATA[Electronic Security]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://wp.embracingchaos.com/2007/05/model_security_.html</guid>
		<description><![CDATA[Why it's good to break the MVC pattern Bruce Perens hit on a really good thing when he wrote a package for Ruby on Rails called Model Security. It's too bad the project is gathering dust. But even if you don't use the whole thing (I haven't been able to) there are some really valuable ideas and chunks of code in there. The idea behind Model Security is to centralize security rules in the model classes. Certain objects can only be accessed by certain users. Perens talks about multi-layered security. But in my mind the real benefit is that you...
]]></description>
			<content:encoded><![CDATA[<h3>Why it&#8217;s good to break the MVC pattern</h3>
<p><a href="http://www.perens.com/">Bruce Perens</a> hit on a really good thing when he wrote a package for <strong>Ruby on Rails</strong> called <a href="http://perens.com/FreeSoftware/ModelSecurity/Tutorial.html">Model Security</a>.&nbsp; It&#8217;s too bad the project is gathering dust.&nbsp; But even if you don&#8217;t use the whole thing (I haven&#8217;t been able to) there are some really valuable ideas and chunks of code in there.</p>
<p>The idea behind Model Security is to centralize security rules in the model classes.&nbsp; Certain objects can only be accessed by certain users.&nbsp; Perens talks about multi-layered security.&nbsp; But in my mind the real benefit is that you can just write the basic rules in one place and not worry about it everywhere else.</p>
<p>An apparent problem with <strong>this strategy </strong>is that it <strong>violates the encapsulation of the MVC pattern</strong>.&nbsp; The only way to put security into the Model part of the pattern is for the Model to know who is trying to access it.&nbsp; The concept of the user is generally localized to the controllers in an MVC pattern.&nbsp; Maybe the view.&nbsp; But definitely not the model.&nbsp; In MVC, the model is supposed to stand entirely on its own and not depend on anything except maybe the persistence mechanism (i.e. the database).&nbsp; So in this way Model Security violates the basic MVC pattern.&nbsp; <strong>Violating well-known design patterns is bad, right?</strong></p>
<p><strong>Absolutely not!</strong>&nbsp; In this case it&#8217;s actually a really good thing.&nbsp; Developers who blindly follow the MVC pattern end up copying and pasting the same security code all over their controllers.&nbsp; Every place that could possibly modify data needs to check security rights.&nbsp; Any place the developer forgets to do this represents a security hole.&nbsp; By putting security rules in your models, you know everything is secure against hackers.&nbsp; &nbsp;Then in your controllers you just need to worry about preventing your users from accidentally seeing security exceptions that would confuse and distress them.&nbsp; <strong>The result is cleaner, more maintainable, more secure code.</strong></p>
<h3>Unit tests</h3>
<p>&quot;<strong>What about unit tests?</strong>&quot;<strong>&nbsp;</strong>I hear you cry.&nbsp; Good<br />
question!&nbsp; For good reasons, we like having unit tests that run on the<br />
models without the web framework in place.&nbsp; But with ModelSecurity, the models depend on the user object, which is generally a part of the web session.&nbsp; So we&#8217;re kinda stuck.&nbsp; Encapsulation is broken, and thus follow our unit tests.&nbsp; The easy answer is to use a<br />
global configuration setting that turns the model security checking on<br />
and off.&nbsp; When you&#8217;re processing a web request, turn it on.&nbsp; When<br />
you&#8217;re running unit tests, leave it off.&nbsp; I&#8217;m thinking this should be pretty easily done in application.rb.&nbsp; Or perhaps through an IOC method in the tests themselves.&nbsp; But I haven&#8217;t actually revived the unit tests in this project so I couldn&#8217;t tell you for sure.&nbsp; Sloppy, I know, but it&#8217;s a lot easier to justify when there&#8217;s only one coder on the project.&nbsp; I&#8217;ll post an update when I dive back into this project.</p>
<h3>Problems with Peren&#8217;s ModelSecurity gem</h3>
<p>I&#8217;ve experienced some <strong>bizarre interactions with FCGI</strong> at least on dreamhost.&nbsp; The ModelSecurity subsystem seems to crash at some point and then opens everything up to allow free access for everybody until I restart the FCGI process.&nbsp; This is absolutely not acceptable.&nbsp; On a somewhat similar note, sometimes basic functions will fail on first execution claiming things like &quot;NoMethodError&quot; but will work fine on subsequent reloads.&nbsp; Having very little interest in debugging this interaction, I have given up on using Perens&#8217; fine-grained rules.&nbsp; The ModelSecurity allows you to specify very carefully which data fields can be accessed by which users under which conditions.</p>
<p>In my app, and many others I can imagine, it&#8217;s enough to set security at the row or object level.&nbsp; This is relatively straightforward with ActiveRecord&#8217;s own callbacks.&nbsp; </p>
<pre>class SecureObject &lt; ActiveRecord::Base&nbsp; has_one :user

&nbsp; #Implement model-based security&nbsp; before_save :check_is_me&nbsp; def after_find&nbsp; &nbsp;&nbsp; &nbsp; # For performance reasons, you have to explicitly define an after_find method.&nbsp; &nbsp;&nbsp; &nbsp; # You can't link it in with &quot;after_find :check_is_me&quot; like other AR callbacks.&nbsp; &nbsp;&nbsp; &nbsp; check_is_me&nbsp; end

&nbsp; def check_is_me&nbsp; &nbsp;&nbsp; &nbsp;if !is_me?&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; raise &quot;Security exception.&nbsp; Not your object!&quot;&nbsp; &nbsp;&nbsp; &nbsp;end&nbsp; end

&nbsp; def is_me?&nbsp; &nbsp;&nbsp; &nbsp;return (User.current) &amp;&amp; (User.current.id == self.user_id)&nbsp; end</pre>
<p>I still use a valuable construct from the ModelSecurity package,<br />
which is the User.current class method which keeps track of who is<br />
currently logged in <strong>thread local storage</strong>.&nbsp; This global variable is what enables us to <strong>break the MVC pattern</strong> by giving the Model access to information about the User from the Controller.&nbsp; Here&#8217;s a relevant snippet from Perens&#8217; user_controller.rb:</p>
<pre>&nbsp; def User.current&nbsp; &nbsp; # This does not refer to the session because the application has set&nbsp; &nbsp; # this from the session in user_setup.&nbsp; &nbsp; Thread.current[:user]&nbsp; end

&nbsp; def User.current=(u)&nbsp; &nbsp; Thread.current[:user] = u

&nbsp; &nbsp; session = Thread.current[:session]

&nbsp; &nbsp; if session.nil?&nbsp; &nbsp;&nbsp; &nbsp;message = &quot;Programming error: Please add \&quot;before_filter :user_setup\&quot; to your application controller. See the ModelSecurity documentation.&quot;

&nbsp; &nbsp;&nbsp; &nbsp;raise RuntimeError.new(message)&nbsp; &nbsp; end

&nbsp; &nbsp; # Don't cause a session store unnecessarily&nbsp; &nbsp; if session[:user] != u&nbsp; &nbsp;&nbsp; &nbsp;session[:user] = u&nbsp; &nbsp; end&nbsp; end</pre>
<h3>The missing ModelSecurity migration</h3>
<p>Another problem is the lack of a <strong>migration</strong> to add the tables required by Perens&#8217; code.&nbsp; Fortunately, it&#8217;s not hard to reverse-engineer using schema.rb and the .sql files that Perens provides.&nbsp; Here&#8217;s <code>db/migrate/###_add_modelsecurity_tables.rb</code>: (the filename is important &#8212; read on)</p>
<pre>class AddModelsecurityTables &lt; ActiveRecord::Migration&nbsp; def self.up&nbsp; &nbsp; create_table &quot;user_configurations&quot;, :force =&gt; true do |t|&nbsp; &nbsp;&nbsp; &nbsp;t.column &quot;email_confirmation&quot;, :integer,&nbsp; &nbsp;:limit =&gt; 3, :default =&gt; 1,&nbsp; :null =&gt; false&nbsp; &nbsp;&nbsp; &nbsp;t.column &quot;email_sender&quot;,&nbsp; &nbsp;&nbsp; &nbsp; :text,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp; :default =&gt; &quot;&quot;, :null =&gt; false&nbsp; &nbsp;&nbsp; &nbsp;t.column &quot;created_on&quot;,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;:timestamp&nbsp; &nbsp;&nbsp; &nbsp;t.column &quot;updated_on&quot;,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;:timestamp&nbsp; &nbsp; end

&nbsp; &nbsp; create_table &quot;users&quot;, :force =&gt; true do |t|&nbsp; &nbsp;&nbsp; &nbsp;t.column &quot;login&quot;,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; :string,&nbsp; &nbsp; :limit =&gt; 40,&nbsp; :default =&gt; &quot;&quot;, :null =&gt; false&nbsp; &nbsp;&nbsp; &nbsp;t.column &quot;name&quot;,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;:string,&nbsp; &nbsp; :limit =&gt; 128, :default =&gt; &quot;&quot;, :null =&gt; false&nbsp; &nbsp;&nbsp; &nbsp;t.column &quot;admin&quot;,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; :integer,&nbsp; &nbsp;:limit =&gt; 1,&nbsp; &nbsp;:default =&gt; 0,&nbsp; :null =&gt; false&nbsp; &nbsp;&nbsp; &nbsp;t.column &quot;activated&quot;,&nbsp; &nbsp; :integer,&nbsp; &nbsp;:limit =&gt; 1,&nbsp; &nbsp;:default =&gt; 0,&nbsp; :null =&gt; false&nbsp; &nbsp;&nbsp; &nbsp;t.column &quot;email&quot;,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; :string,&nbsp; &nbsp; :limit =&gt; 80,&nbsp; :default =&gt; &quot;&quot;, :null =&gt; false&nbsp; &nbsp;&nbsp; &nbsp;t.column &quot;cypher&quot;,&nbsp; &nbsp;&nbsp; &nbsp; :text,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;:default =&gt; &quot;&quot;, :null =&gt; false&nbsp; &nbsp;&nbsp; &nbsp;t.column &quot;salt&quot;,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;:string,&nbsp; &nbsp; :limit =&gt; 40,&nbsp; :default =&gt; &quot;&quot;, :null =&gt; false&nbsp; &nbsp;&nbsp; &nbsp;t.column &quot;token&quot;,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; :string,&nbsp; &nbsp; :limit =&gt; 10,&nbsp; :default =&gt; &quot;&quot;, :null =&gt; false&nbsp; &nbsp;&nbsp; &nbsp;t.column &quot;token_expiry&quot;, :timestamp&nbsp; &nbsp;&nbsp; &nbsp;t.column &quot;created_on&quot;,&nbsp; &nbsp;:timestamp&nbsp; &nbsp;&nbsp; &nbsp;t.column &quot;updated_on&quot;,&nbsp; &nbsp;:timestamp&nbsp; &nbsp;&nbsp; &nbsp;t.column &quot;lock_version&quot;, :integer,&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;:default =&gt; 0,&nbsp; :null =&gt; false&nbsp; &nbsp; end

&nbsp; &nbsp; add_index &quot;users&quot;, [&quot;login&quot;], :name =&gt; &quot;login&quot;&nbsp; &nbsp; add_index &quot;users&quot;, [&quot;email&quot;], :name =&gt; &quot;email&quot;&nbsp; end

&nbsp; def self.down&nbsp; &nbsp; drop_table :users&nbsp; &nbsp; drop_table :user_configurations&nbsp; endend</pre>
<p>
In classically annoying Rails style, if the class name of your migration doesn&#8217;t perfectly &quot;match&quot; the&nbsp; filename then rake migrate will fail mysteriously with an unhelpful error message and a mile-long stack-trace with none of your code in it.&nbsp; <em>E.g.</em> if you name the above file <code>005_add_model_security_tables.rb</code> (note the extra underscore between &quot;model&quot; and &quot;security&quot;) you&#8217;ll get an error message like this:</p>
<pre>rake aborted!uninitialized constant AddModelSecurityTables</pre>
<p>or if you run <code>rake migrate --trace</code> you&#8217;ll get this stack trace:</p>
<pre>** Invoke migrate (first_time)** Invoke db:migrate (first_time)** Invoke environment (first_time)** Execute environment** Execute db:migraterake aborted!uninitialized constant AddModelSecurityTables/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:266:in `load_missing_constant'/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:452:in `const_missing'/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/dependencies.rb:464:in `const_missing'/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/inflector.rb:250:in `constantize'/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.1/lib/active_support/core_ext/string/inflections.rb:148:in `constantize'/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/migration.rb:366:in `migration_class'/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/migration.rb:346:in `migration_classes'/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/connection_adapters/mysql_adapter.rb:248:in `inject'/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/migration.rb:342:in `each'/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/migration.rb:342:in `inject'/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/migration.rb:342:in `migration_classes'/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.2/lib/active_record/migration.rb:330:in `migrate'</pre>
<p>Then you might grep your code for &quot;AddModelSecurityTables&quot; and find that it&#8217;s not there because you have &quot;AddModelsecurityTables&quot; (difference in upper- vs. lower-case S).&nbsp; This kind of thing is why <a href="http://www.embracingchaos.com/2007/03/scaling_ruby_to.html">Rails is still a bad choice for complex projects</a> &#8212; a small hard-to-see typo results in the system not running and providing almost no useful feedback about what&#8217;s wrong.&nbsp; And yet we keep trying to use Rails.&nbsp; Because it seems to have so much potential.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.embracingchaos.com/2007/05/model_security_.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Offbrain: Externalizing Memory</title>
		<link>http://www.embracingchaos.com/2007/05/offbrain_extern.html</link>
		<comments>http://www.embracingchaos.com/2007/05/offbrain_extern.html#comments</comments>
		<pubDate>Thu, 03 May 2007 09:57:19 +0000</pubDate>
		<dc:creator>leodirac</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Transhumanism]]></category>
		<category><![CDATA[User Experience]]></category>

		<guid isPermaLink="false">http://wp.embracingchaos.com/2007/05/offbrain_extern.html</guid>
		<description><![CDATA[I'm ready to introduce a little pet project to the world: Offbrain Mobile Memory Services. Right now it's a very simple web app that just keeps track of lists of things. The only thing that makes it at all interesting right now is that the UI is optimized for display on mobile browsers. It's modeled after the fabulous mobile gmail interface. Offbrain's pages are typically between 1k and 1.5k total -- they load very snappily on very slow mobile links. (Assuming dreamhost hasn't swapped the app or the database into virtual memory -- a perennial problem with cheap shared hosting.)...
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m ready to introduce a little pet project to the world: <a href="http://offbrain.com">Offbrain Mobile Memory Services</a>.&nbsp; Right now it&#8217;s a very simple web app that just keeps track of lists of things.&nbsp; The only thing that makes it at all interesting right now is that the UI is optimized for display on mobile browsers.&nbsp; </p>
<p>It&#8217;s modeled after the fabulous <a href="http://m.gmail.com">mobile gmail interface</a>.&nbsp; Offbrain&#8217;s pages are typically between 1k and 1.5k total &#8212; they load very snappily on very slow mobile links.&nbsp; (Assuming dreamhost hasn&#8217;t swapped the app or the database into virtual memory &#8212; a perennial problem with cheap shared hosting.)&nbsp; And by using extremely simple HTML (think 1994) the pages display very nicely on a 240&#215;240 pixel screen like you&#8217;ll find on a cell phone.</p>
<p>The idea of the service is to take notepad and list functionality that has been standard in PDAs and PIMs forever, and move it into the information cloud.&nbsp; Make it accessible through web, e-mail and SMS so it&#8217;s accessible anywhere you have a cellphone.&nbsp; This way you&#8217;ll never forget to bring your shopping list to the store again because you&#8217;ll always have your phone with you.&nbsp; Even better, since it&#8217;s stored in the cloud, you and your family members can share a group list, which would never have been possible with paper or traditional PDAs.</p>
<p>My buddy Ben and I even came up with a cool way to monetize this free-to-consumers service as a business.&nbsp; We entered the idea in the UW Business Plan Competition which provided me the necessary motivation to build the beta that&#8217;s now live and to do the necessary research into how to connect it to a real SMS gateway.&nbsp; (Thanks to Jordan Schwartz for all the tips.)</p>
<p>My real goal of course here is to support the <a href="http://www.robolucion.org">upcoming robot revolution</a> by encouraging people to move more of their active minds into computers.&nbsp; Encourage is a strong word.&nbsp; Enable.&nbsp; Moral capitalism requires offering services that are mutually beneficial to all parties with full disclosure of all known information.&nbsp; By this criterion I think I&#8217;m totally in the clear so long as I explain to y&#8217;all what I&#8217;m up to.</p>
<p>Once I actually wire up the SMS interface, I&#8217;m gonna totally use this all the time.&nbsp; Anytime I want to remember something and I don&#8217;t have my journal in front of me, I&#8217;m just gonna whip out my cell phone and send a text message to <a href="http://offbrain.com">my external brain</a> (my Offbrain) so it&#8217;ll remember it for me.</p>
<p>And yes, despite all my whining, I wrote it in Ruby on Rails.&nbsp; Annoying as the language is for complex projects, it works really nicely for a quick and dirty app like this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.embracingchaos.com/2007/05/offbrain_extern.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Problems Scaling Ruby to Complex Systems</title>
		<link>http://www.embracingchaos.com/2007/03/scaling_ruby_to.html</link>
		<comments>http://www.embracingchaos.com/2007/03/scaling_ruby_to.html#comments</comments>
		<pubDate>Sun, 04 Mar 2007 17:02:27 +0000</pubDate>
		<dc:creator>leodirac</dc:creator>
				<category><![CDATA[Personal Growth]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://wp.embracingchaos.com/2007/03/scaling_ruby_to.html</guid>
		<description><![CDATA[I'm pretty annoyed with Ruby right now. At least I feel that way. Looking a little deeper I realize the source of the annoyance is, like usual, my own shortcomings. My friends and I embarked on a software project a while back. I helped talked the group into using Ruby on Rails as the framework over choices like Java or .net because I was excited about it. Many had reservations. Today I'm annoyed at myself for not listening to them more. The biggest problem with an uncompiled language is that there's no compiler to tell you when you've screwed something...
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m pretty annoyed with Ruby right now.&nbsp; At least I feel that way.&nbsp; Looking a little deeper I realize the source of the annoyance is, like usual, my own shortcomings.&nbsp; My friends and I embarked on a software project a while back.&nbsp; I helped talked the group into using Ruby on Rails as the framework over choices like Java or .net because I was excited about it.&nbsp; Many had reservations.&nbsp; Today I&#8217;m annoyed at myself for not listening to them more.</p>
<p><strong>The biggest problem with an uncompiled language is that there&#8217;s no compiler</strong> to tell you when you&#8217;ve screwed something up.&nbsp; The incredible power and flexibility you get from Ruby&#8217;s loose dynamic typing and mixin inheritance style means that the IDE and compiler really have no idea what&#8217;s valid when you type it.&nbsp; Compare this to Eclipse for Java or Visual Studio for .net where once you type &#8216;objectname-dot&#8217; there&#8217;s a list of valid methods you can call and what kinds of parameters they take.&nbsp; If you get it wrong, there&#8217;s a red squiggly underline saying something is wrong before you&#8217;re on to the next line of code.&nbsp; </p>
<p>Yesterday 3 reasonably good software engineers took a solid 3 hours to figure out that we were passing the wrong class of argument into a method.&nbsp; The problem was exacerbated by the behind-the-scenes magic that Rails does to try to make your life easier.&nbsp; We were passing a Tmail object into ActionMailer.receive, which might seem to make sense since the receive method that everybody who uses ActionMailer writes expects a Tmail object as an input.&nbsp; But we had forgotten that you&#8217;re not supposed to call this method.&nbsp; In fact ActionMailer makes it impossible to directly call the method we wrote.&nbsp; Instead you&#8217;re forced to call the class method, which we had forgotten expects a string as input that it parses into a Tmail object for you.&nbsp; And like usual, the error message is useless.&nbsp; <strong>Bad error messages are the single biggest flaw with Ruby on Rails</strong> IMHO.&nbsp; (Maybe just the easiest to fix compared to the other problems.)&nbsp; This was particularly frustrating because we spent an entire day tracking down something that any strongly typed language would have caught instantly.</p>
<p>For a long time, I&#8217;ve argued that <strong>people should use the highest level programming language they can</strong> afford to.&nbsp; A huge advantage of pointerless languages is that you can&#8217;t make pointer mistakes.&nbsp; It&#8217;s simply not possible to write that kind of bug in the higher level language.&nbsp; Coding therefore become faster and more reliable than in a lower-level language.&nbsp; The only cost is run-time performance, and if you&#8217;re writing server code as most of us do these days, then scalability is generally not limited by performance.&nbsp; I had assumed that this analogy would continue from managed-code languages up to the hottest new scripting language that seems like it&#8217;s flexibility might fulfill OO&#8217;s promise of code re-use.&nbsp; Today I&#8217;ve changed my mind.&nbsp; <strong>Ruby is not a higher level language than C# or Java.</strong>&nbsp; </p>
<p>Conceivably, a really good IDE could make up for a lot of this.&nbsp; But due to the run-time binding in Ruby it would never be perfect.&nbsp; When selecting a development system, generally I think the language itself is really unimportant compared to the quality of the tools and libraries available.&nbsp; OO languages are generally about the same.&nbsp; But IDE&#8217;s matter so much.&nbsp; And libraries determine how much you have to write yourself vs. using what others have done before you. </p>
<p>A friend asked me if I was writing this as a warning or a cry for help.&nbsp; It&#8217;s both.&nbsp; It&#8217;s a warning about the scalability limits of Ruby.&nbsp; Many people intuitively suspect that Ruby on Rails won&#8217;t scale well, but they confuse the different types of scalability.&nbsp; The most common complaint about Ruby is that its runtime performance is too slow to scale well.&nbsp; As <a href="http://www.amazon.com/gp/product/0596102356?ie=UTF8&amp;tag=httpwwwaddgco-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0596102356">Cal Henderson&#8217;s wonderful book</a><img width="1" height="1" border="0" src="http://www.assoc-amazon.com/e/ir?t=httpwwwaddgco-20&amp;l=as2&amp;o=1&amp;a=0596102356" style="border: medium none  ! important; margin: 0px ! important;" /> on website scalability points out, raw performance does not matter if you can add more servers, which you can with RoR.&nbsp; But as I learned yesterday, <strong>Ruby on Rails does not scale well in terms of complexity</strong>.&nbsp; A friend once aptly pointed out that <a href="http://www.43things.com">43 things</a> was the largest site anybody had managed to build in RoR to date.&nbsp; The current state of tools and libraries and aspects of the language itself make it extremely difficult to write and maintain large complex projects with many developers.</p>
<p>It&#8217;s also a cry for help, but not for our particular project.&nbsp; You&#8217;ll see it soon enough.&nbsp; It&#8217;s a request that if you&#8217;re working on Ruby or Rails, please invest in the tools and the robustness of the libraries.&nbsp; The error messages in Rails are total crap, as I&#8217;ve <a href="http://www.embracingchaos.com/2006/10/misleading_erro.html">mentioned</a> <a href="http://www.embracingchaos.com/2006/12/how_to_fix_fail.html">a couple times</a> before.&nbsp; And the IDE&#8217;s really need to improve if the framework is going to see major use beyond hobbyists.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.embracingchaos.com/2007/03/scaling_ruby_to.html/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How to fix failed migrations for &#8220;Lost connection to MySQL&#8221;</title>
		<link>http://www.embracingchaos.com/2006/12/how_to_fix_fail.html</link>
		<comments>http://www.embracingchaos.com/2006/12/how_to_fix_fail.html#comments</comments>
		<pubDate>Sat, 16 Dec 2006 22:30:46 +0000</pubDate>
		<dc:creator>leodirac</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://wp.embracingchaos.com/2006/12/how_to_fix_fail.html</guid>
		<description><![CDATA[Yet another in the long series of "why does rails give such useless error messages?" I could migrate in the development environment fine, but when i tried to migrate in the test environment, I got this: C:\dev\radrailsws\snorb>rake migrate RAILS_ENV=test (in C:/dev/radrailsws/snorb) rake aborted! Mysql::Error: Lost connection to MySQL server during query: SELECT version FROM schema_info After a bit of digging I thought it was because the mysql account in the test environment is different from development, so I ran this to grant full permissions: mysql> grant all on snorb_test.* to unit_test_user Query OK, 0 rows affected (0.00 sec) But that...
]]></description>
			<content:encoded><![CDATA[<p>Yet another in the long series of &quot;why does rails give such useless error messages?&quot;&nbsp; I could migrate in the development environment fine, but when i tried to migrate in the test environment, I got this:</p>
<pre>C:\dev\radrailsws\snorb&gt;rake migrate RAILS_ENV=test(in C:/dev/radrailsws/snorb)rake aborted!Mysql::Error: Lost connection to MySQL server during query: SELECT version FROMschema_info</pre>
<p>After a bit of digging I thought it was because the mysql account in the test environment is different from development, so I ran this to grant full permissions: </p>
<pre>mysql&gt; grant all on snorb_test.* to unit_test_userQuery OK, 0 rows affected (0.00 sec)</pre>
<p>But that didn&#8217;t work either.&nbsp; I ended up having to let the test environment use the root mysql account, which I didn&#8217;t want to do, but that certainly fixed the problem.&nbsp; I&#8217;ve suspected there&#8217;s something funny going on with the test environment database credentials for a while, but I can&#8217;t quite pin it down.</p>
<p>Here&#8217;s the full set of errors I was getting from the system in case it helps anybody find this problem&#8230;<em>&nbsp;</em></p>
<pre>C:\dev\radrailsws\snorb&gt;rake migrate RAILS_ENV=test(in C:/dev/radrailsws/snorb)rake aborted!Mysql::Error: Lost connection to MySQL server during query: SELECT version FROMschema_info

(See full trace by running task with --trace)

C:\dev\fritz\radrailsws\snorb&gt;config\environments\test.rb

C:\dev\fritz\radrailsws\snorb&gt;rake migrate --trace(in C:/dev/fritz/radrailsws/snorb)** Invoke migrate (first_time)** Invoke db:migrate (first_time)** Invoke environment (first_time)** Execute environment** Execute db:migraterake aborted!Mysql::Error: Lost connection to MySQL server during query: SELECT version FROMschema_infoc:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract_adapter.rb:120:in `log'c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:184:in `execute'c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:336:in `select'c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:179:in `select_one'c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/migration.rb:307:in `current_version'</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.embracingchaos.com/2006/12/how_to_fix_fail.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Missing GEM causes misleading &#8220;use_transactional_fixtures&#8221; error</title>
		<link>http://www.embracingchaos.com/2006/10/misleading_erro.html</link>
		<comments>http://www.embracingchaos.com/2006/10/misleading_erro.html#comments</comments>
		<pubDate>Tue, 31 Oct 2006 07:27:34 +0000</pubDate>
		<dc:creator>leodirac</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://wp.embracingchaos.com/2006/10/misleading_erro.html</guid>
		<description><![CDATA[A lot of people out there on the net are getting frustrated by this error message coming out of their unit tests: undefined method `use_transactional_fixtures=' for Test::Unit::TestCase:Class (NoMethodError) I was recently getting this in my unit tests on my continuous integration server. The problem is that this has message nothing to do with the actual error. Rake has this bad habit of silently swallowing useful errors. Sometimes is just stops without saying anything, and other times it gives a completely incorrect message like this one. In my case, the problem was a missing gem on the continuous integration server. I've...
]]></description>
			<content:encoded><![CDATA[<p>A lot of people out there on the net are getting frustrated by this error message coming out of their unit tests:</p>
<p><code>&nbsp; &nbsp; undefined method `use_transactional_fixtures=' for Test::Unit::TestCase:Class (NoMethodError)</code></p>
<p>I was recently getting this in my unit tests on my continuous integration server.&nbsp; The problem is that this has message nothing to do with the actual error.&nbsp; Rake has this bad habit of silently swallowing useful errors.&nbsp; Sometimes is just stops without saying anything, and other times it gives a completely incorrect message like this one.</p>
<p><strong>In my case, the problem was a missing gem on the continuous integration server.</strong></p>
<p>I&#8217;ve been working on patches to address these bad-error-message issues, but I haven&#8217;t yet gone through the effort of figuring out how to contribute them into the master source tree.&nbsp; I haven&#8217;t developed a patch to catch the root cause behind the &#8216;use_transactional_fixtures&#8217; error above yet.&nbsp; But here&#8217;s one that catches database config errors and a bunch of others that would otherwise be silently swallowed:</p>
<p>Go into /usr/lib/ruby/gems/1.8/gems/rails-1.1.6/lib/tasks/testing.rake and change the <code>task :test</code> method to read:</p>
<pre>desc 'Test all units and functionals'task :test do&nbsp; error_place=&quot;&quot;&nbsp; Rake::Task[&quot;test:units&quot;].invoke&nbsp; &nbsp;&nbsp; &nbsp; rescue error_place += &quot;test:units: #{$!}&quot;&nbsp; Rake::Task[&quot;test:functionals&quot;].invoke rescue error_place += &quot;test:functionals: #{$!}&quot;&nbsp; &nbsp; if File.exist?(&quot;test/integration&quot;)&nbsp; &nbsp; Rake::Task[&quot;test:integration&quot;].invoke rescue error_place += &quot;test:integration: #{$!}&quot;&nbsp; end

&nbsp; raise &quot;Test failures in #{error_place}&quot; if error_place != &quot;&quot;end</pre>
<p>Compare to the <a href="http://dev.rubyonrails.org/svn/rails/trunk/railties/lib/tasks/testing.rake">official version</a>.&nbsp; Note what happens to exceptions: nothing.&nbsp; This patch has been invaluable for configuration on my CI server.&nbsp; To repeat, this patch does not address the &quot;use_transactional_fixtures&quot; error.&nbsp; When I figure out a patch for that one I&#8217;ll post it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.embracingchaos.com/2006/10/misleading_erro.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Chinese characters in Mysql: Dont forget the collation</title>
		<link>http://www.embracingchaos.com/2006/10/chinese_charact.html</link>
		<comments>http://www.embracingchaos.com/2006/10/chinese_charact.html#comments</comments>
		<pubDate>Tue, 17 Oct 2006 02:30:00 +0000</pubDate>
		<dc:creator>leodirac</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://wp.embracingchaos.com/2006/10/chinese_charact.html</guid>
		<description><![CDATA[I recently conquered another oddity in using chinese characters in MySql. Apparently, it's not enough to set the database's character set to UTF-8. You also need to set the collation to a utf-8 collation. You might think the collation is only important for sorting, but theres' more to it. If you have selected a case-insensitive collation, then it is also used to determine equality. If the collation doesn't understand character boundaries properly, then you run into strange problems. The database was convinced two very different chinese characters were the same because their UTF-8 encodings when interpretted as 1252 had similar...
]]></description>
			<content:encoded><![CDATA[<p>I recently conquered another oddity in using chinese characters in MySql.&nbsp; Apparently, it&#8217;s not enough to set the database&#8217;s character set to UTF-8.&nbsp; You also need to set the collation to a utf-8 collation.&nbsp; You might think the collation is only important for sorting, but theres&#8217; more to it.&nbsp; If you have selected a case-insensitive collation, then it is also used to determine equality.&nbsp; If the collation doesn&#8217;t understand character boundaries properly, then you run into strange problems.&nbsp; The database was convinced two very different chinese characters were the same because their UTF-8 encodings when interpretted as 1252 had similar characters, maybe only differing in case or accent.</p>
<p>So if you&#8217;re having trouble with unicode characters in mysql, try running this command:</p>
<p><code>mysql&gt; alter database chinesedb collate utf8_bin</code></p>
<p>Next step is figuring out how to put this into an ActiveRecord migration.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.embracingchaos.com/2006/10/chinese_charact.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby + MySql weirdness</title>
		<link>http://www.embracingchaos.com/2006/10/ruby_mysql_weir.html</link>
		<comments>http://www.embracingchaos.com/2006/10/ruby_mysql_weir.html#comments</comments>
		<pubDate>Sun, 01 Oct 2006 22:43:06 +0000</pubDate>
		<dc:creator>leodirac</dc:creator>
				<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://wp.embracingchaos.com/2006/10/ruby_mysql_weir.html</guid>
		<description><![CDATA[I'm posting this because I didn't see any quick answers on google when looking for other people having my problem. Recently all the unit tests for one of my Ruby on Rails projects started failing mysteriously. The continuous integration server didn't report any problems, but on my windows dev box (where I use instant rails) nothing would pass. The errors came out like: 15) Error: test_update(Admin::ConnectionControllerTest): ActiveRecord::StatementInvalid: Mysql::Error: Lost connection to MySQL server during query: DELETE FROM connections c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract_adapter.rb:120:in `log' c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:184:in `execute' c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:199:in `delete' c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:283:in `delete_existing_fixtures' c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:256:in `create_fixtures' c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:256:in `create_fixtures' c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/database_statements.rb:51:in `transaction' c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:255:in `create_fixtures' c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:794:in `silence' c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:248:in `create_fixtures' c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:565:in `load_fixtures'...
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m posting this because I didn&#8217;t see any quick answers on google when looking for other people having my problem.&nbsp; Recently all the unit tests for one of my Ruby on Rails projects started failing mysteriously.&nbsp; The continuous integration server didn&#8217;t report any problems, but on my windows dev box (where I use <a href="http://rubyforge.org/projects/instantrails/">instant rails</a>) nothing would pass.&nbsp; The errors came out like:</p>
<pre> 15) Error:test_update(Admin::ConnectionControllerTest):ActiveRecord::StatementInvalid: Mysql::Error: Lost connection to MySQL server during query: DELETE FROM connections&nbsp; &nbsp; c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract_adapter.rb:120:in `log'&nbsp; &nbsp; c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:184:in `execute'&nbsp; &nbsp; c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/mysql_adapter.rb:199:in `delete'&nbsp; &nbsp; c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:283:in `delete_existing_fixtures'&nbsp; &nbsp; c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:256:in `create_fixtures'&nbsp; &nbsp; c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:256:in `create_fixtures'&nbsp; &nbsp; c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/connection_adapters/abstract/database_statements.rb:51:in `transaction'&nbsp; &nbsp; c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:255:in `create_fixtures'&nbsp; &nbsp; c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/base.rb:794:in `silence'&nbsp; &nbsp; c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:248:in `create_fixtures'&nbsp; &nbsp; c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:565:in `load_fixtures'&nbsp; &nbsp; c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:512:in `setup_with_fixtures'&nbsp; &nbsp; c:/dev/fritz/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.4/lib/active_record/fixtures.rb:547:in `setup'</pre>
<p>The problem apparently is caused by the fact that I put a password on the mysql login credentials in the test environment.&nbsp; Removing the password on the login made it work just fine.&nbsp; So I guess something about the ruby mysql driver didn&#8217;t like the way my mysql server was configured.&nbsp; Anyway, upgrading to <a href="http://dev.mysql.com/downloads/mysql/5.0.html">Mysql 5.0</a> (from 4.1) fixed everything.&nbsp; Not sure if this is a problem with the version of instant rails I have, or something about my database config, or if one of the libraries autoupdated to a non-compatible version, but it&#8217;s fixed now so I don&#8217;t much care.</p>
<p>Hope this helps anybody else out there who runs into a similar problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.embracingchaos.com/2006/10/ruby_mysql_weir.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
