Sunday, August 07, 2005

Rough Riding on Rails

I have a small, one man project for a friend that I don't want to spend much time or hosting money on. I dove head first into Rails (and Ruby) yesterday. I'm running Ruby 1.8.2 and Rails 0.13.1 on OS X 10.3. I've known Java cold for some time, so I can't say I'm enjoying the fish out of water feeling. Naturally, I ran into two obscure errors which burned almost an entire day out of my weekend. First, I tried to use the Salted Hash Login Generator. After running the generator, I get the following exception when I try to run the unit tests:
/test/mocks/test/time.rb:5: undefined method `cattr_accessor' for
Time:Class (NoMethodError)
from /Users/crazybob/projects/vesco
.back/config/../test/mocks/test/time.rb:3:in `class_eval' from /Users/crazybob/projects/vesco.back/config/../test/mocks/test/time.rb:3:in `class_eval' from /Users/crazybob/projects/vesco.back/config/../test/mocks/test/time.rb:3 from /usr/local/lib/ruby/site_ruby/1.8/rubygems/specification.rb:1:in `require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems/specification.rb:1 from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:396:in `require' from /usr/local/lib/ruby/site_ruby/1.8/rubygems.rb:396 from /Users/crazybob/projects/vesco.back/config/environment.rb:48:in `require' from /Users/crazybob/projects/vesco.back/config/environment.rb:48 from ./test/unit/../test_helper.rb:5:in `require' from ./test/unit/../test_helper.rb:5 from ./test/unit/localization_test.rb:3:in `require' from ./test/unit/localization_test.rb:3 from /usr/local/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/rake_test_loader.rb:5:in `load' from /usr/local/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/rake_test_loader.rb:5 from /usr/local/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/rake_test_loader.rb:5:in `each' from /usr/local/lib/ruby/gems/1.8/gems/rake-0.5.4/lib/rake/rake_test_loader.rb:5
I contacted the author, but only one other person has encountered this problem, and he couldn't explain it. He even copied the other person's code over to his machine and everything worked fine. This particular exception occurs because the required cattr_accessor method has not been introduced yet. The Rails code introduces this method, but I have no idea why it's not happening; probably an ordering issue. I tried modifying the mock class to not call this method, but I just ran into another exception (and so on until I gave up). Maybe it has something to do with my Ruby build. The exception occurs in the environment.rb file. Doesn't the server load this as well? That seems to work. I abandoned the Salted Hash Login Generator for the simpler but much less functional Login Generator and got back to the task at hand. Next, I thought I'd take scaffold for a spin. I generated scaffolds for a domain class named Request. The unit tests passed and the list view came up fine, but the new Request view blew up. It couldn't find some obscure field in the Request class. It took me a while to figure out that my Request class was completely replacing the HTTP Request class. Aren't they in different packages? How could Rails allow this? In any case, I renamed my domain class and everything worked as expected. Now that I'm up and running, I can see some of the appeal, but Rails has been over hyped. I'm starting to think some Java developers subject themselves to a lot of pain with badly designed development evironments. Of course they feel better when they move to Rails; it has a pretty decent build by default. You can't blame lousy builds and slow server deployments on Java. Also, Java code certainly looks more verbose (type checking requires more code), but if you know how to take advantage of an IDE, you don't actually manually write much more code. Exploring Rails for the first time, I definitely miss type checking and my IDE. I really like the idea of scaffold. It obviously can't generate production worthy code, but it definitely gives you a good starting point. Staring at a blank text editor can be daunting for a new user in any language. Scaffold builds an end to end working foundation. I think this appeals to slightly better than cut and paste coders (such as myself at the moment).