A much more level-headed person than I wrote an in-depth essay on why Ruby is not quite ready for prime time.
I was initially excited about Ruby on Rails. What got my attention was scaffolding. I’ve been told it’s a hack, but how can you not get excited when an application automagically knows when you add or substract fields from the database it’s pointing to?
But then RoR 2.0 came out, and scaffolding, as far as I could tell, was broken. Ok, maybe not entirely broken but…it might as well be. You see, now to scaffold, instead of just editing a config file to tell the application where the database is located, you have to actually go through some odd song and dance to have the initialization of the application construct the tables. At least, that’s what I gathered from the patchy documentation I could find on the issue.
It might seem like a petty fine line I’m drawing here, but think about it. Putting in a layer of complication in a process that was the reason so many people were fired up about RoR is the equivalent of Apple discarding its entire iPod line.
Sorry, Ruby. The magic is gone, but I’m hoping in a few years after you’ve matured we can have dinner and try again.
April 30th, 2008 at 12:39 pm
Hi. Just happened to stumble across this post and actually had something that may help you.
What you’re referring to is called dynamic scaffolding, and there are several alternatives at http://www.ruby-forum.com/topic/134691 if you really require it — supposedly quite a bit fancier, as well. You still had to generate the models and controllers, even then however, prior to adding the call to dynamically create the scaffold. What was happening was that Rails was generating the same code you now see written to the file in the current version, just not writing it to the file.
The part that really enabled the magic you were referring to in your post, namely, database introspection — knowing about columns in the database tables and using them automatically, is part of ActiveRecord, the Rails ORM layer.
This is very spiffy stuff. You can create a table named people, for instance, with the columns called id, first_name, last_name. Then you add a single model called person.rb to your app’s models directory, and it looks like this:
class Person < ActiveRecord::Base
end
That’s it. It will understand that the plural of Person is people, and look for a table with that name in the DB. You can then do stuff like:
ernie = Person.find_by_first_name(“Ernie”)
ernie.last_name = “Miller”
ernie.save
And then the DB is updated. If you add a new column, called e-mail, all your objects will now have an e-mail attribute automatically created.
I’m still a relative newcomer to the Rails world, but don’t be so quick to write it off. There’s a lot to be liked here. Check out how simple metaprogramming can be in Ruby — I have a couple of posts that show some examples:
http://thebalance.metautonomo.us/2008/04/04/simplified-active-directory-authentication/
http://thebalance.metautonomo.us/2008/02/07/simple-model-search-with-rails/
May 2nd, 2008 at 7:26 am
Ernie: Sorry it took so long to approve your comment, and thank you so much for the helpful comment!