<?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>Peter Krantz &#187; Rails</title>
	<atom:link href="http://www.peterkrantz.com/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.peterkrantz.com</link>
	<description>A blog about technology, visualization, music and unmanned vehicle experiments</description>
	<lastBuildDate>Mon, 12 Jul 2010 14:47:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Rails vs Grails vs Django models</title>
		<link>http://www.peterkrantz.com/2009/rails-grails-django-models/</link>
		<comments>http://www.peterkrantz.com/2009/rails-grails-django-models/#comments</comments>
		<pubDate>Wed, 24 Jun 2009 16:58:47 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Applications]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[domain modeling]]></category>
		<category><![CDATA[grails]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/?p=281</guid>
		<description><![CDATA[Coming back to Rails after being away from some time in Django land I discovered a huge difference in how Rails and Django treats your models...]]></description>
			<content:encoded><![CDATA[<p>Coming back to Rails after being away from some time in Django land I discovered a huge difference in how Rails, Grails and Django treats your models. In Django and Grails you can look at a model class and see all the properties it has:</p>
<pre class="brush: python;">
class Organization(models.Model):
    name = models.CharField(max_length=255)
    url = models.URLField(verify_exists=False)
    orgtype = models.ForeignKey(OrgType)
</pre>
<p>The same model class in Rails typically looks like this:</p>
<pre class="brush: ruby;">
class Organization &lt; ActiveRecord::Base
    belongs_to :OrgType
end
</pre>
<p>&#8230;and in Grails it is more specific like Django:</p>
<pre class="brush: groovy;">
class Organization {
  String name
  String url
  static belongsTo = OrgType
  OrgType orgtype
}
</pre>
<p>It took me a while to remember that in Rails, parts of the model design is actually stored in the database schema instead of in the Ruby code. Peculiar don&#8217;t you think, given that everything else in a Rails app is nicely declared in Ruby code? There are of course benefits to both approaches, but I have started adding comments in the Rails model classes to be able to remember what properties they have without peeking in the Db. Typically I have a number of half-baked projects on my laptop and from time to time I forget what they do and these comments help me remember.</p>
<p>Check out more examples here:</p>
<ul>
<li><a href="http://docs.djangoproject.com/en/dev/topics/db/models/#topics-db-models">Django models</a></li>
<li><a href="http://www.tutorialspoint.com/ruby-on-rails/rails-models.htm">Rails models</a></li>
<li><a href="https://www.ibm.com/developerworks/java/library/j-grails02128/">Grails models</a></li>
</ul>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.peterkrantz.com%2F2009%2Frails-grails-django-models%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" title="I like this" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:auto;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2009/rails-grails-django-models/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Software architects as management deadwood</title>
		<link>http://www.peterkrantz.com/2008/software-architects/</link>
		<comments>http://www.peterkrantz.com/2008/software-architects/#comments</comments>
		<pubDate>Sat, 02 Feb 2008 19:31:55 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Trends]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/2008/software-architects/</guid>
		<description><![CDATA[Two interesting quotes from Dietrich Kappe: So no, we don&#8217;t hire architects. We hire developers. In a small team, there is no room for management deadwood. I agree completely. My view is that the title &#8220;Software architect&#8221; is a misnomer for what most architects in the software industry do, or at least what they should [...]]]></description>
			<content:encoded><![CDATA[<p>Two interesting quotes from <a href="http://blogs.pathf.com/agileajax/2008/02/but-where-are-a.html">Dietrich Kappe</a>:</p>
<blockquote><p>So no, we don&#8217;t hire architects. We hire developers. In a small team, there is no room for management deadwood.</p></blockquote>
<p>I agree completely. My view is that the title &#8220;Software architect&#8221; is a misnomer for what most architects in the software industry do, or at least what they should be doing. </p>
<p>It is part of the weird trend that career advancement means getting away from actual programming for some reason. Maybe that is part of a bigger problem when the only way to get a higher pay is to become a manager of some sort? A couple of years ago, most programmers I knew aimed for a project management position. Programming was a dirty job that you had to put up with during the first years in consulting.</p>
<p>When my title was &#8220;business analyst&#8221; I tried to do as much programming I could and I haven&#8217;t regretted that for a moment. In fact, I believe that more people from the business side should get involved in programming to get a better understanding of the fundamental principles. For example, it would be great if business people could write their own acceptance tests and with the booming trend of DSL:s you will probably get involved anyway. </p>
<blockquote><p>If you&#8217;ve made the transition from a hierarchical environment to an agile, self-organizing team, you know what I&#8217;m saying. You won&#8217;t ever want to go back.</p></blockquote>
<p>Absolutely. It is the same thing as discovering things like Ruby/Python/Rails: it makes you wonder what the hell you were doing earlier. In many ways I feel sorry for young software developers that go straight into Rails or similar frameworks today. They are not as appreciative as the rest of us:-)</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.peterkrantz.com%2F2008%2Fsoftware-architects%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" title="I like this" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:auto;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2008/software-architects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Will Rails ever run on IronRuby?</title>
		<link>http://www.peterkrantz.com/2008/rails-on-ironruby/</link>
		<comments>http://www.peterkrantz.com/2008/rails-on-ironruby/#comments</comments>
		<pubDate>Mon, 28 Jan 2008 22:23:14 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/2008/rails-on-ironruby/</guid>
		<description><![CDATA[I met Ola Bini at the local Geeknight the other day and we had a brief chat about platforms, Ruby and RDF among other things. Ola mentioned that he wasn&#8217;t sure that Rails wuld run on IronRuby &#8211; Microsoft&#8217;s implementation of Ruby for the CLR. I have been following what John Lam has been writing [...]]]></description>
			<content:encoded><![CDATA[<p>I met Ola Bini at the local Geeknight the other day and we had a brief chat about platforms, Ruby and RDF among other things. Ola mentioned that he wasn&#8217;t sure that Rails wuld run on <a href="http://www.ironruby.net/">IronRuby</a> &#8211; Microsoft&#8217;s implementation of Ruby for the CLR.</p>
<p>I have been following what John Lam has been writing about their progress (and I correctly <a href="http://www.peterkrantz.com/2006/using-ruby-as-a-net-language/">predicted him joining Microsoft</a>:-) and it appears that running Rails is a goal of the IronRuby project. But, will that be of interest to Microsoft? MS recently launched the first version of an <a href="http://weblogs.asp.net/scottgu/archive/2007/10/14/asp-net-mvc-framework.aspx">MVC framework for the ASP.NET platform</a>. This seems like an attempt to satisfy the curiosity of .net developers that have seen screen casts and office mates develop apps in Ruby on Rails.  The framework is part of the Visual Studio 2008 offerings.</p>
<p>If you were able to deploy a Rails app by dropping a DLL on a Windows web server I can see Rails popularity exploding. The .net platform seems to occupy a mid-level segment of application hosting operations, right where Rails development seem to be.</p>
<p>Only time will tell I guess.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.peterkrantz.com%2F2008%2Frails-on-ironruby%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" title="I like this" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:auto;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2008/rails-on-ironruby/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Prism &#8211; web apps as desktop apps</title>
		<link>http://www.peterkrantz.com/2007/prism-web-desktop-apps/</link>
		<comments>http://www.peterkrantz.com/2007/prism-web-desktop-apps/#comments</comments>
		<pubDate>Mon, 24 Dec 2007 11:58:35 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Trends]]></category>
		<category><![CDATA[Usability]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/2007/prism-web-desktop-apps/</guid>
		<description><![CDATA[When people started making applications available in the browser a number of interaction challenges appeared. How do you launch a web app compared to a desktop app? How do you prevent people from navigating away from your app? The Mozilla people have been hard t work with Prism &#8211; basically a customized version of Firefox, [...]]]></description>
			<content:encoded><![CDATA[<p>When people started making applications available in the browser a number of interaction challenges appeared. How do you launch a web app compared to a desktop app? How do you prevent people from navigating away from your app? The <a href="http://starkravingfinkle.org/blog/2007/10/webrunner-becomes-prism-a-mozilla-labs-project/">Mozilla people</a> have been hard t work with <a href="http://wiki.mozilla.org/Prism">Prism</a> &#8211; basically a customized version of Firefox, which lets you create desktop apps pre-configured to load a certain URL at startup. The desktop app is launched like any other application. Pretty sweet as the user experience becomes more consistent. You can also customize the application icon and <a href="http://wiki.mozilla.org/Prism/Config">other parameters</a>.</p>
<p>I have been running the beta version of <a href="http://mailplaneapp.com/">MailPlane</a> which provides at desktop version of Gmail (using Webkit). Apart from keeping Gmail in a separate branded window it also provides standard mac shortcut keys as well as desktop integration for screenshots and other file related things. Pretty sweet.</p>
<p>I was interested to see if Prism could provide a similar experience. Prism is currently an early beta at version 0.8 so it isn&#8217;t fair to expect too much of it. The <a href="http://wiki.mozilla.org/Prism#Wishlist">feature wish list</a> looks great.</p>
<p>Launching prism and creating a Gmail app worked great. However, Prism currently has some issues:</p>
<ul>
<li>It consumes close to 100% of a CPU core on my MacBook which makes it unusable for now.</li>
<li>Font size can not be adjusted (should be a parameter?).</li>
<li>There is a white space at the bottom of the app screen which reduce valuable screen estate. <img src='http://www.peterkrantz.com/wp-content/uploads/2007/12/prism-whitespace.png' alt='prism 0.8 white space bug' class="illustration"/></li>
</ul>
<p>I would also like to see an option to map access keys to native OS keys (e.g. Prism forwards ⌘+r as alt+r to the web app). This would allow users to work with the application in a way indistinguishable from a desktop application. also, if there was a way to interact with files (drag and drop etc) à la MailPlane I could see how Prism could be the preferred choice of many application developers in the future.</p>
<p>Couple it with a stand alone Ruby on Rails app (by using <a href="http://joyeur.com/2007/03/22/joyent-slingshot">Joyent&#8217;s Slingshot</a>) and you have a whole new way of developing applications that work offline, online and in a coherent way with other desktop apps. The future is bright!</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.peterkrantz.com%2F2007%2Fprism-web-desktop-apps%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" title="I like this" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:auto;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2007/prism-web-desktop-apps/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>When PHP makes sense</title>
		<link>http://www.peterkrantz.com/2007/when-php-makes-sense/</link>
		<comments>http://www.peterkrantz.com/2007/when-php-makes-sense/#comments</comments>
		<pubDate>Sat, 08 Sep 2007 20:42:31 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/2007/when-php-makes-sense/</guid>
		<description><![CDATA[I have been looking into development frameworks for a web based software product. I want the product to be able to be installed on a variety of platforms, including Windows server with IIS. First I was looking at creating the app in ASP.NET and make it run under Mono. Unfortunately I can't find an <a href="http://www.peterkrantz.com/2007/aspnet-mvc-frameworks/">MVC framework for ASP.NET</a> that works the way I want. Ruby on Rails has really lowered the threshold of what I can put up with in the form of configuration and learning curve. Damn you DHH and your rapid web framework:-)]]></description>
			<content:encoded><![CDATA[<p>I have been looking into development frameworks for a web based software product. I want the product to be able to be installed on a variety of platforms, including Windows server with IIS. First I was looking at creating the app in ASP.NET and make it run under Mono. Unfortunately I can&#8217;t find an <a href="http://www.peterkrantz.com/2007/aspnet-mvc-frameworks/">MVC framework for ASP.NET</a> that works the way I want. Ruby on Rails has really lowered the threshold of what I can put up with in the form of configuration and learning curve. Damn you DHH and your rapid web framework:-)</p>
<p>Ruby on Rails runs happily on Linux and in Java environments thanks to JRuby. It does not work well with IIS yet (until IronRuby is here I guess). There is, however, interesting work being done in the <a href="http://www.codeplex.com/RORIIS">RORIIS project</a> (also see Dorje McKinnon&#8217;s <a href="http://dorjem.blogspot.com/2007/02/to-setup-rails-on-iis-and-enable-it-for.html">Set up Rails on IIS blog post</a>). The only problem I have is that I have heard a lot of reports where Rails under IIS isn&#8217;t working properly and that the RORIIS bundles several components that Windows server managers may find scary.</p>
<p>Django and Turbogears does not seem to work well under IIS either. For <a href="http://code.djangoproject.com/wiki/DjangoOnWindowsWithIISAndSQLServer">Django, the PyISAPI is required</a> and apparently it hasen&#8217;t been actively developed for a while leading to bugs in the latest version of Django (you also have to run Python 2.4 instead of 2.5).</p>
<p><a href="http://turbogears.org/">Turbogears</a> seems to be <a href="http://docs.turbogears.org/1.0/BehindIIS">close to work on IIS</a>. Only problem is that it requires a <a href="http://www.saltypickle.com/Home/16">reverse proxy filter</a> that hasen&#8217;t been actively developed since 2005 which makes me wary about using it.</p>
<p>So, looking at <a href="http://www.symfony-project.com/">Symfony, the Rails inspired PHP framework</a>, I am beginning to wonder if that would be the best choice right now. The <a href="http://www.symfony-project.com/cookbook/1_0/web_server_iis">installation instructions for Windows/IIS</a> seem straightforward. Symfony recommends the <a href="http://www.isapirewrite.com/">commercial ISAPIRewrite filter</a> (lite version os free). For IIS7 it looks like Microsoft is stepping up to the plate with a <a href="http://blogs.iis.net/bills/archive/2006/10/31/PHP-on-IIS.aspx">decent Fast CGI module</a>. Performance seems to be adequate too. </p>
<p>So, right now, Symfony/PHP seems like a decent choice for this app if I can live with the <a href="http://www.bitstorm.org/edwin/en/php/">intricacies of PHP</a>. Who would have thought&#8230;</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.peterkrantz.com%2F2007%2Fwhen-php-makes-sense%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" title="I like this" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:auto;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2007/when-php-makes-sense/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Looking for ASP.NET MVC Frameworks&#8230;</title>
		<link>http://www.peterkrantz.com/2007/aspnet-mvc-frameworks/</link>
		<comments>http://www.peterkrantz.com/2007/aspnet-mvc-frameworks/#comments</comments>
		<pubDate>Sat, 18 Aug 2007 15:37:09 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Rails]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/2007/aspnet-mvc-frameworks/</guid>
		<description><![CDATA[I have been looking for an open source alternative to the default way of buildig web sites in ASP.NET with Visual Studio. After having build a couple of applications with Ruby on Rails it hard to go back to the Page Controller pattern that Microsoft introduced in ASP.NET. Coming back to the ASP.NET page event [...]]]></description>
			<content:encoded><![CDATA[<p>I have been looking for an open source alternative to the default way of buildig web sites in ASP.NET with Visual Studio. After having build a couple of applications with Ruby on Rails it hard to go back to the <a href="http://martinfowler.com/eaaCatalog/pageController.html">Page Controller pattern</a> that Microsoft introduced in ASP.NET. Coming back to the ASP.NET page event model makes it clear that they created it for VB6 application developers that were used to Windows forms-centered development. Apparently they didn&#8217;t want to those developers to have to learn about HTTP and HTML to be able to write applications.</p>
<p> I guess from a marketing persepective it may have been the right choice (for Microsoft), but right now it feels like a horrible mess for me. So, I spent a couple of hours researching the alternatives. There are a number of commercial packages available (LLBLGen et al) but I only found three that looked interesting for my purposes:</p>
<ol>
<li><a href="http://www.castleproject.org/">MonoRail</a>: The Ruby on Rails-inspired framework with an ActiveRecord component based on NHibernate.</li>
<li><a href="http://www.springframework.net/">Spring.NET: A port of the Spring framework for Java.</a></li>
<li><a href="http://www.codeplex.com/PixelDragonsMVC">PixelDragons MVC</a>: this looks promising but seems to lack real world use? Requires further investigation.</li>
</ol>
<p>Looking at the <a href="http://www.springframework.net/docs/1.1-RC1/reference/html/quickstarts.html">quickstart documentation for Spring.NET</a> I decided that it was way too much configuration involved to get things running. Ruby on Rails has definitely lowered my tolerance for lengthy project setups. </p>
<p>The <a href="http://www.castleproject.org/monorail/gettingstarted/">getting started tutorial for MonoRail</a> looked much more pleasant. The MonoRail framework comes with a nice MSI installer and a <a href="http://www.castleproject.org/castle/vsintegration.html">custom project wizard</a> to quickly set up a project skeleton in Visual Studio 2005. There is even an option to create an associated test project from the start.</p>
<p>After some initial problems with getting the application talking to my SQL Server 2005 database (Microsoft has drastically increased security for the 2005 version resulting in a number of configuration steps to be able to talk to the db at all) I had a sample app going. Users of Ruby on Rails will feel at home since you can do nice stuff like:</p>
<p>public void CreateUser()<br />
{<br />
      User owner = new User();<br />
      owner.FirstName = &#8220;Peter&#8221;;<br />
      owner.LastName = &#8220;Krantz&#8221;;<br />
      owner.Create();<br />
}</p>
<p>Then I wanted to try a TDD approach and this is where I am currently stuck. The MonoRail project wizard creates a sample test project with a sample test of a controller. However, according to people in the forum that approach is deprecated and a different way of testing controllers is described on the MonoRail wiki. But that approach does not work for testing your model classes and there is no information on how to get an application context to do that. Or maybe I have missed it when Googling for a solution.</p>
<h2>Can I have just the O/RM please?</h2>
<p>So, if I go back to the Page Controller pattern, can I please have an open source persistence framework that allows me to write code like above? I was happy to find this <a href="http://csharp-source.net/open-source/persistence">rather extensive list of persistence frameworks</a>. The only problem is that most of them are not actively developed anymore. Or, they have simply disappeared as Microsoft is <a href="http://www.gotdotnet.com/workspaces/default.aspx">shutting down the GotDotNet website</a> where many of them are/were hosted.</p>
<p>If you stick to the default pattern in ASP.NET you have a wealth of excellent tutorials and documentation from Microsoft and others. Going off the beaten track seems more difficult though. Hopefully the MonoRail issue will be solved and I can use it for my product idea.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.peterkrantz.com%2F2007%2Faspnet-mvc-frameworks%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" title="I like this" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:auto;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2007/aspnet-mvc-frameworks/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Checking for Model Classes Before Using Them in Rails Migrations</title>
		<link>http://www.peterkrantz.com/2007/models-in-migrations-tip/</link>
		<comments>http://www.peterkrantz.com/2007/models-in-migrations-tip/#comments</comments>
		<pubDate>Thu, 07 Jun 2007 11:39:27 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/2007/models-in-migrations-tip/</guid>
		<description><![CDATA[If you are using model objects in migrations (e.g. for inserting data) you should make sure that the migration works even if that model class is removed. I discovered this when setting up a new development environment and running all migrations in an empty database. Let&#8217;s say you have the following migration code: class InsertCounties [...]]]></description>
			<content:encoded><![CDATA[<p>If you are using model objects in migrations (e.g. for inserting data) you should make sure that the migration works even if that model class is removed. I discovered this when setting up a new development environment and running all migrations in an empty database.</p>
<p>Let&#8217;s say you have the following migration code:</p>
<p>class InsertCounties < ActiveRecord::Migration<br />
  def self.up<br />
    County.create :code => &#8217;10&#8242;, :name => &#8216;Blekinge&#8217;<br />
    County.create :code => &#8217;20&#8242;, :name => &#8216;Dalarna&#8217;<br />
  end<br />
end</p>
<p>This assumes that the County model is available when the migration is run. If you checked out the most recent version of your code from svn it is possible that it doesn&#8217;t contain the County model and the migration will fail. To check if County is available before trying to use it <a href="http://redhanded.hobix.com/inspect/methodCheckDefined.html">we can use Ruby&#8217;s defined?</a> like this:</p>
<p><strong>Update:</strong> No we can&#8217;t. defined? always returns false inside an ActiveRecord migration for some reason (maybe the class isn&#8217;t loaded before the actual call?). We have to use a begin&#8230;rescue&#8230;end block instead:</p>
<p>class InsertCounties < ActiveRecord::Migration<br />
  def self.up<br />
    begin<br />
      County.create :code => &#8217;10&#8242;, :name => &#8216;Blekinge&#8217;<br />
      County.create :code => &#8217;20&#8242;, :name => &#8216;Dalarna&#8217;<br />
    rescue<br />
      puts &#8220;Could not add data&#8230;&#8221;<br />
    end<br />
  end<br />
end</p>
<p>This way the rest of the migrations will run.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.peterkrantz.com%2F2007%2Fmodels-in-migrations-tip%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" title="I like this" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:auto;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2007/models-in-migrations-tip/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Bringing Ruby to the .NET environment</title>
		<link>http://www.peterkrantz.com/2007/bringing-ruby-to-the-net-environment/</link>
		<comments>http://www.peterkrantz.com/2007/bringing-ruby-to-the-net-environment/#comments</comments>
		<pubDate>Tue, 05 Jun 2007 09:04:15 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Trends]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/2007/bringing-ruby-to-the-net-environment/</guid>
		<description><![CDATA[Things are heating up in the Ruby-as-a-dotnet-language area. Martin Fowler voiced his concerns on Microsoft not being able to look at source code and therefore having trouble implementing Ruby properly. Microsoft, with John Lam in the cockpit, is implementting Ruby for the .net platform (if you have been reading my previous blog posts I predicted [...]]]></description>
			<content:encoded><![CDATA[<p>Things are heating up in the Ruby-as-a-dotnet-language area. <a href="http://martinfowler.com/bliki/RubyMicrosoft.html">Martin Fowler voiced his concerns</a> on Microsoft not being able to look at source code and therefore having trouble implementing Ruby properly. Microsoft, with <a href="http://www.iunknown.com/">John Lam</a> in the cockpit, is implementting Ruby for the .net platform (if you have been reading my previous blog posts I predicted way <a href="http://www.peterkrantz.com/2006/using-ruby-as-a-net-language/">back in february 2006</a> that John Lam would get scooped up my Microsoft:-).</p>
<p><a href="http://ola-bini.blogspot.com/2007/06/there-can-be-only-one-tale-about-ruby.html">Ola Bini is also concerned</a> about Microsoft not letting ther developers look at the Ruby implementation. If you remember the whole SCO debacle I guess it isn&#8217;t that strange. Microsoft is in the position where software they develop potentially may end up in millions of computers. Apparently the US legal system awards damages in proportion to this. Thus, any issues with a Ruby implementation on .net can quickly become costly.</p>
<p>It is all quite bizarre. Does this mean that the Microsoft version of the Ruby language is different from the &#8220;original&#8221; Ruby? I guess we will never know. Developers will probably write a lot of Ruby code that runs happily on the CLR. Rails applications will be deployed. But I am sure that there will be &#8220;special cases&#8221; where IronRuby will differ from &#8220;original&#8221; Ruby.</p>
<p>Therefore is was refreshing to see that Queensland University of Technology are progressing steadily with <a href="http://plas2003.fit.qut.edu.au/Ruby.NET/">their Ruby.NET implementation</a>. Currently you can actually compile a Ruby script into a .NET 2.0 assembly that other CLR languages can talk to. This may be the spearhead into the <a href="http://www.peterkrantz.com/2007/enterprise-rails-deployment/">other half of enterprise deployment options</a>.</p>
<p>All in all the future of software development looks bright. Will developers that invested a lot of time in Java or C# switch? Or will they move on to maintaining applications?</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.peterkrantz.com%2F2007%2Fbringing-ruby-to-the-net-environment%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" title="I like this" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:auto;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2007/bringing-ruby-to-the-net-environment/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Working with UTF-8 in PDF::Writer and Ruby on Rails</title>
		<link>http://www.peterkrantz.com/2007/utf8-in-pdf-writer/</link>
		<comments>http://www.peterkrantz.com/2007/utf8-in-pdf-writer/#comments</comments>
		<pubDate>Thu, 31 May 2007 14:26:00 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/2007/utf8-in-pdf-writer/</guid>
		<description><![CDATA[Googling for information on how to use PDF::Writer shows that there are many european developers frustrated with the lack of UTF-8 support in PDF::Writer. As Ruby on Rails works great with UTF-8 these days this can be a bit of an issue. Part of the problem lies in the fact that the PDF specification (at [...]]]></description>
			<content:encoded><![CDATA[<p>Googling for information on how to use <a href="http://ruby-pdf.rubyforge.org/pdf-writer/index.html">PDF::Writer</a> shows that there are many european developers frustrated with the lack of UTF-8 support in PDF::Writer. As Ruby on Rails works great with UTF-8 these days this can be a bit of an issue. </p>
<p>Part of the problem lies in the fact that the PDF specification (at least up to 1.6) does not support UTF-8 (you can use UTF-16 if you like). I had the misfortune of plowing thorugh it a couple of years ago when developing a PDF form filler library for a customer (don&#8217;t ask).</p>
<p>In Ruby on Rails, this is easy to solve as long as you only use Latin characters with diacritics. The solution is to switch encoding back to <a href="http://en.wikipedia.org/wiki/ISO_8859-15">ISO-8859-15</a> for text strings you feed to PDF::Writer. </p>
<p>A simple extension to the String class will do the trick:</p>
<p>class String<br />
  require &#8216;iconv&#8217;<br />
  def to_iso<br />
    c = Iconv.new(&#8216;ISO-8859-15&#8242;,&#8217;UTF-8&#8242;)<br />
    c.iconv(self)<br />
  end<br />
end</p>
<p>If you are working in Rails you can put this code in the lib folder (I usually call the file string_extensions.rb). </p>
<p>Then, when you call the text method on your PDF::Writer intance you can easily pass a correctly encoded string.</p>
<h2>Overriding PDF::Writer text method</h2>
<p>A much cleaner approach, as Aníbal describes in the comment below, is to override PDF::Writer&#8217;s text method.</p>
<p>Put the following code in a file called pdfwriter_extensions.rb (or whatever you choose to call it) in your lib directory:</p>
<p>CONVERTER = Iconv.new( &#8216;ISO-8859-15//IGNORE//TRANSLIT&#8217;, &#8216;utf-8&#8242;)</p>
<p>module PDF<br />
	class Writer<br />
		alias_method :old_text, :text</p>
<p>		def text(textto, options = {})<br />
			old_text(CONVERTER.iconv(textto), options)<br />
		end</p>
<p>	end<br />
end</p>
<p>In your controller that handles the PDF output you add:</p>
<p>  require &#8216;pdf/writer&#8217;<br />
  require &#8216;pdfwriter_extensions&#8217;</p>
<p>&#8230;after which you can use PDF::Writer like in the tutorial:</p>
<p>    pdf = PDF::Writer.new<br />
    pdf.select_font &#8220;Helvetica&#8221;, :encoding => nil<br />
    pdf.text &#8220;User name: <b>#{@user.name}</b>&#8220;, :font_size => 16, :justification => :left<br />
    send_data pdf.render, :disposition => &#8216;inline&#8217;, :filename => &#8220;user_details.pdf&#8221;, :type => &#8220;application/pdf&#8221;</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.peterkrantz.com%2F2007%2Futf8-in-pdf-writer%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" title="I like this" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:auto;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2007/utf8-in-pdf-writer/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>Enterprise Rails Deployment Getting Closer (thanks to Ola Bini and the JRuby team)&#8230;</title>
		<link>http://www.peterkrantz.com/2007/enterprise-rails-deployment/</link>
		<comments>http://www.peterkrantz.com/2007/enterprise-rails-deployment/#comments</comments>
		<pubDate>Mon, 07 May 2007 19:21:43 +0000</pubDate>
		<dc:creator>Pete</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Trends]]></category>

		<guid isPermaLink="false">http://www.peterkrantz.com/2007/enterprise-rails-deployment/</guid>
		<description><![CDATA[<img src='http://www.peterkrantz.com/wp-content/uploads/2007/05/enterprise.jpg' alt='Dongbu Financial Center in Seoul. Picture by Ian Muttoo' class="illustration"/>You may wonder if the title is supposed to be ironic. Wasn't "enterprise" and "rails" forbidden to be mentioned in the same sentence?

Let's forget about that for a while. Ola Bini and the JRuby team is quickly moving forward with something I would consider a breakthrough in Rails deployment options. In fact, it could well mean a breakthrough in Rails adoption in many organizations.]]></description>
			<content:encoded><![CDATA[<p><img src='http://www.peterkrantz.com/wp-content/uploads/2007/05/enterprise.jpg' alt='Dongbu Financial Center in Seoul. Picture by Ian Muttoo' class="illustration"/>You may wonder if the title is supposed to be ironic. Wasn&#8217;t &#8220;enterprise&#8221; and &#8220;rails&#8221; forbidden to be mentioned in the same sentence?</p>
<p>Let&#8217;s forget about that for a while. <a href="http://ola-bini.blogspot.com/">Ola Bini</a> and the JRuby team is quickly moving forward with something I would consider a breakthrough in Rails deployment options. In fact, it could well mean a breakthrough in Rails adoption in many organizations.</p>
<h2>Why (some) IT-managers like Rails but don&#8217;t like deploying it</h2>
<p>When I was a consultant I talked to many IT-managers that had heard about Ruby on Rails. They were intrigued by the fact that Ruby and Rails were created for developers rather than machines. Most of them realized that developer time costs more than computer performance today (although some of them were still spending money at developers writing unnecessarily complicated code to run fast on hardware that costs less than 20 developer hours).</p>
<p>However, these IT-managers weren&#8217;t too keen on deploying Rails applications in their environment. You see, if you spent the last five years creating a homogenous server environment it is likely that you have invested a lot in it. The following typically applies in this type of environment:</p>
<ul>
<li>You have specialized server administrators that know how to deploy, run and monitor aplications in the environment.</li>
<li>One or more large vendors have sold you expensive software in which you run your applications.</li>
<li>The same vendors have sent you a lot of marketing material telling you how lucky you are to be running their software and that your competitors are running the same thing.</li>
<li>Developing software for the environment requires expensive consultants. This, obviously, means that you get professionals.</li>
<li>Software typically runs fine in the environment.</li>
</ul>
<p>The environment may be Java or .NET. The investment is typically bigger if it is Java.</p>
<p>And then Rails developers come to you and say that your investment in this homogenous environment should be thrown away. You staff should be retrained and deployment no longer takes a week. Obviously these developers must be lying. </p>
<h2>Why Ola Bini and the Jruby team may increase Rails adoption</h2>
<p>Any day now it will be possible to wrap up your <a href="http://headius.blogspot.com/2006/12/another-step-toward-rails-war-files.html">Rails app in a WAR-file</a> and put it right into a Java server environment. It may already work for all I know. Server administrators may not even see the difference between a Rails app and a regular Java app.</p>
<p>When this is easy to do I believe that Rails will se a much larger adoption in larger organizations (with these types of environments). And from there it will only get better. Thoughtworks seem to be in on <a href="http://studios.thoughtworks.com/2007/5/7/mingle-to-run-on-jruby">the same track</a>.</p>
<p>I guess both Sun and Microsoft realized the importance of being able to run Rails applications in existing environments. Sun is supporting JRuby and Microsoft <a href="http://www.iunknown.com/">hired John Lam</a> to make Ruby run on the CLR (they already had <a href="http://blogs.msdn.com/hugunin/archive/2004/10/11/240841.aspx">Jim Hugunin</a> make it possible to run Python code fast on the CLR). </p>
<p><strong>Interesting times are ahead!</strong></p>
<p>I guess we will have to thank Ola and the JRuby team for that&#8230;</p>
<p>Update: I was just told that <a href="http://flickr.com/photos/x180/245186478/">James DD snapped a picture of me</a> sitting next to Ola at Railsconf London. It is a small world after all.</p>
<p>Update 2: And here are instructions on how to <a href="http://letsgetdugg.com/view/How_to_deploy_a_self_contained_Rails_application_on_Tomcat,_painlessly">create a WAR file of a Rails app</a> for deployment in Tomcat.</p>
<div id="facebook_like"><iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.peterkrantz.com%2F2007%2Fenterprise-rails-deployment%2F&amp;layout=standard&amp;show-faces=true&amp;width=450&amp;action=like&amp;font=arial&amp;colorscheme=light" scrolling="no" title="I like this" frameborder="0" allowTransparency="true" style="border:none; overflow:hidden; width:450px; height:auto;"></iframe></div>]]></content:encoded>
			<wfw:commentRss>http://www.peterkrantz.com/2007/enterprise-rails-deployment/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
