Rails vs. ASP.NET (Really, Ruby vs C#)

Where have I been...why the lack of posts: a) holidays, b) knee injury playing basketball (that required surgery to repair) has slowed me down, c) recently, I've started to work on a project where ASP.NET using C# was the requirement.

So, I haven't been working in Rails for a few weeks and it's been a few years since I've used ASP.NET or C#, so I've had to jump back into it a little to refresh myself.

Now, look, I'm not trying to start a religious war here: ASP.NET and Rails each have their own benefits and drawbacks. However, I would like to say this: for simple web sites Rails is so much easier.

Here's a simple example: I've got a URL stored in the database, such as http://www.mysite.com/foo/fee/foh.htm and I need to get the foh.htm (which isn't stored).

ASP.NET with C#

    public string FileName
{
get
{
char[] delim = { '/' };
string[] a = this.Url.Split(delim);
return a[a.Length - 1];
}
}

Rails with Ruby
  def filename
self.url.split('/').last
end

I'm sure I'm not the first person to make this comparison. I just felt compelled to speak out about the many moments during the day where it takes me several minutes longer to do something with ASP.NET and C# than Ruby and Rails.

How to Make Subversion via HTTP work with RailsMachine (and Capistrano)

Last night I setup my site on RailsMachine. Overall, it was a very pleasant experience. One bugaboo that I ran into:

I have my Subversion repository setup using http, not svn+ssh. The repository is hosted at Joyent and I don't recall why I set it up this way, but there must have been a reason.

Anyhoo...so, I'm plugging away with RailsMachine and using Capistrano for the first time and it's all pretty sweet, except for I can't seem to access my svn repository. Cap would reach the point in the script where it made the HTTP request and I would see the HTTP authentication, but I had no way to type in my user/pass combo, and it would fail.

Long story short: RailsMachine requires that you run Cap using a user called "deploy", and those are the credentials that Cap passes via HTTP Authentication to the svn repository. So, I was able to get it to work by simply creating a user for my svn repository called "deploy" with the same password as "deploy" on my RailsMachine server. Everything works fine now!

more on attachment_fu on windows

In my previous post about attachment_fu (with rmagick) on windows, I did something sort of silly in the #create action of my controller: Windows required a little time to catch up because the file system loaded the file slower that attachemnt_fu needed it. To solve that problem, I added "sleep 5" immediately before MyObject#save.

The problem with that hack is every time I need to #save I have to remember to insert the "sleep 5" hack. That's a mistake waiting to happen. So, I moved the sleep to the model, like so:


class MyObject < ActiveRecord::Base
def before_save
sleep 5 ## <<-- pauses so Windows can catch up.
end
end

It's much more logical that this code is part of the model because the delay is fundamentally a part saving the object, not a part of responding to an action.

This also address the notion of keeping your controllers skinny and your models fat. Jamis Buck blogs very eloquently about this notion here.