Showing posts with label ruby. Show all posts
Showing posts with label ruby. Show all posts

Thursday, January 25, 2007

Notes on getting Ruby on Rails working on my Powerbook 15

Used darwin ports to install ruby and rb-rubygems

I’m using z-shell so I needed to edit the

'~/Library/init/zsh/environment'

file to make sure that

'/opt/local/bin'

was the first folder on my path. Then I simply did a

gem install rake
gem install rails

This sounds simple but it only took 5 hours of digging to get right!

Come on Apple. If you are going to include Ruby then make sure you install it correctly.

Rails, Plural table names - lame

O.K. I’ve been working with Rails for several weeks now and am loving the ease for cranking out websites. Good stuff.

But…

(and that’s a big butt)

For some insane reason the developers of Rails decided plural table names was a convention worth promoting by having it as the default.

Most experienced DBAs will tell you that the name of a table should describe what one record in that table would represent. Who would recommend plural table names? Developers seem to like plural names because they equate database tables with Collections (think java.util.List). I guess I come from a more traditional background where I think of tables as set theory.

Naming guidelines aside there is another reason not to go down this route. Rails then has to be smart enough to parse the plurals for almost every noun in the English dictionary.

What short-circuited in the developer’s brains? They develop this slick environment and then slap in some hacky idea. I think it is only useful to add to the perceived “wow” factor that the Rails enthusiasts get at conferences. yee-ha!

Luckily there is a work-around to make Rails work just as nicely with singular table names.

Thanks to this post on justinram.wordpress.com for providing the answer on how to switch off this really stupid bug in rails:

Add the following to the bottom of your config/environment.rb file:

# Include your application configuration below
ActiveRecord::Base.pluralize_table_names = false

Design by convention

Final thing that “really grinds my gears” (Family Guy) is that it goes against the grain of “design by convention” that is Rails major contribution to the web space. Why would all my controllers, views, helpers, etc be called Employee and my table name be Employees?

Why would my code refer to “Sheep” and my table name be “Sheep”. Well, maybe that wasn’t a good example.

I guess in the end there is a difference between convention magic: “Hey, all my MVC objects are named the same so I don’t have to configure them - that makes sense” and spooky “under the covers” magic “Hey I magically figured out that your Alumnus class should be related to the Alumni table”

It is a good thing that Rails has that call to the Dictionary.com web service to get the plural name for every model.