This is a read-only archive!

Rails impressions

So after a weekend of Ruby on Rails'ing, as expected, I do really love it. I hit a couple "gotchas" but nothing show-stopping.

Rails does so many things automatically that at times you can't keep track of it. This is not fun when it comes time to track down a bug when your script crashes.

I have yet to really understand start-to-finish what goes on when Rails handles a request. I know that Apache (via htaccess rewrites in my case) or your server of choice pipes incoming requests to a Rails dispatcher CGI script. Then it somehow knows to parse the URL and route it according to the routes you set up. Then Rails auto-requires a whole bunch of files from a whole bunch of directories, apparently selected via some sort of magic hand-waving algorithm. Then control is passed to one of your controller files, which potentially loads a dizzying array of templates in the form of views and layouts and partials, and has access to all kinds of things in the helpers and lib directories.

When working in the various model/controller/view files, via some magic, lots of things are visible that probably wouldn't be in a normal Ruby script. You set an instance variable in one place and then magically it's visible in all kinds of other places. Lots of your user-defined classes are visible everywhere with no need to require any of their source files.

I've also already been bitten by accidental collisions with some of Ruby's naming conventions. Any column called "type" in any table will cause horrible and non-intuitive breakage, because Ruby by default uses a column called "type" for some kind of funky table inheritance scheme. Rails also expects table names to be plurals of model names, which leads to some fun when you have a model called "Armor" and you have to make a table called "armors"(?). You can inform the Rails Inflector that the plural of "armor" is "armor", but it's kind of annoying to have to. Those are not the only such problems I've run into, either; namespace pollution and naming convention oddness in Rails is everywhere. But at least in a great many cases Rails give you a way to override or ignore the defaults.

(Note to self: Wordpress chokes on any post containing the text ".htaccess". Why?)

April 30, 2007 @ 7:42 AM PDT
Cateogory: Programming
Tags: Ruby


Quoth Jason on April 30, 2007 @ 9:21 AM PDT

Did you read Agile Web Dev. from December '05? Or the 2nd edition from 2006 (or... perhaps it was early 2007, I can't recall).

The first book was a great primer, but the one thing that SUCKED was databases. The 2nd edition released migrations, and boy-oh-boy do they make things dead-freaking-simple.

You should almost never have any problems (especially naming conventions) with models and databases if you're using Rails with Migrations, because you input your database schema in a quasi-SQL / quasi-Ruby(YML) mash, and it does all the rendering for you when you rake db.

If you didn't read the second edition of the book, get a hold of it AND RE-READ IT ALL!!! Seriously, the difference is absolutely stellar.

Quoth Brian on April 30, 2007 @ 9:54 AM PDT

I do have the second version. I must admit glossing over the migrations parts because my database is already fully built from a previous version of my site. Oops. Maybe I'll go back and re-read those.

But I actually had little to no problem with the database, other than all my "type" fields.