A Weekend with Rails

August 5, 2007 | Comments Off

Friday afternoon I started my first project with rails. Ok, technically it’s my second project. I tried doing rails for the sake of rails but I never get anywhere that way. I need a real project with a real purpose (if it succeeds) but not so important that I can’t live without. I found the right project on Friday surfing the web, and basically spent all of Friday night and the vast majority of Saturday working on it. The rest are my impressions.

As for ruby itself, I’m pretty pleased with it. It has a lot of the trappings of perl, particularly the array and hash methods behave identically. I can’t say the language ever really caused a problem. Rails itself is fairly nice. The scaffolding provides a great way to prototype without having to do a lot of coding on the un-important areas. So far I’ve also written no SQL code, at least not in ruby. I created a handful of views in the database, but that’s about it. The trouble I’ve have/had, and I imagine the limitation most people bump into has to do with the models. The expectations are rigid and I haven’t solved for certain problems yet. Like how do I get to extra data in a link table? And how do I deal with tables that have no primary key? I’m sure these are documented but I’ve only run into those troubles in the latter part of yesterday.

The documentation for ruby and rails is excellent. The rails API and the Ruby core documentation are easily navigable. The errrors seem to be less well documented. Some of my biggest frustrations have come in tracking down errors thrown by the app. The other rough spots have been when the rails table guessing regime hasn’t worked out. As an example, I had a table called passes, and a class called Pass. When I declared an association of “has_many :passes” the software guessed my foreign key as “pas_id” (the right answer was “pass_id”). The last bit I haven’t figured out yet is how to layer in authentication and authorization. Currently the app doesn’t require rigorous authentication – all of the users are trustworthy – but that’s just a coincidence.

The default scaffolding is functional but not robust, in any sense. It doesn’t allow you to navigate relationships. I was directed towards ActiveScaffold project. It’s largely a drop-in replacement for scaffolds but it exposes much more of the relationships. In some cases too much. For example, in my application suppose there are users and passes in a many-to-many relationship. A user should be selecting which passes he owns (modifying a link table) not modifying the passes themselvs. ActiveScaffold exposes both with no easy way to suppress the behavior. I’ve been using the ‘subform’ control to control which fields get displayed in the subform context, and that’s a quick middleground, but again, my users are very informal.

The ActiveScaffold recommendation came by way of the nice folks in #rubyonrails on irc.freenode.org. Unlike the more popular web development platforms (perl or php), there is an unusually low frequency of stupid/easy questions and a high tolerance for such occurrences. I attribute this to lack of widespread ruby adoption, I think popularity brings in the unwashed masses, and the masses destroy the tolerance, but that’s for another day.

Overall I’m fairly impressed with Ruby. The touted ability to start see and make progress with small amounts of code is not hype. When you throw in ActiveScaffold you even have something that looks largely pretty. The real question becomes how challenging it is to replace scaffolding with real code and from what I’ve seen it’s on par with php or mod_perl. Perhaps even a little better with the built-in concept of layouts (templates basically). The application in question is no small case either. Currently I have 26 tables, 15 models, and 14 controllers. Not bad for a day and a half.

No Comments yet

Sorry, the comment form is closed at this time.