Laughably WrongNew meaning to "running on magic"Earth Date 07/14/2010 |
I went through a mildly rocky road during a recent deployment of a Jruby on Rails app to Tomcat. This seemed like a fairly trivial job and I look forward to my next one. I’ve plugged in the code to a class that was the source of numerous deployments because I wasn’t catching errors until runtime. How many errors do you see?
class Referral < AciveRecord::Base
set_table_name :referral
primary_key :referral_id
belongs_to :person => :foreign_key => person_id
has_one :contract_placement => :foreign_key => referral_id
end
As I went through the code I counted five lines that were bad, four if you don’t count the whitespace that really doesn’t provide any value and could just be deleted. “AciveRecord” gave me a little giggle , but primary_key! What exactly was that supposed to do. Whoa Tarzan! doubling up on assignment operators doesn’t work, especially when you don’t even have the entity. Let’s put it together a little nicer for comparison sake.
class Referral < ActiveRecord::Base
set_table_name :referral
set_primary_key :referral_id
belongs_to :person, :foreign_key => :person_id
has_one :contract_placement, :foreign_key => :referral_id
end
My proof of concept ran for more than a year on my desktop with fairly heavy use, no crashes and no errors. This was all thanks to the fact that I apparently never called the Referral class in my application. When I rolled it out to a Tomcat server the whole game changed and every one of those errors got spit back into my console.
So I guess the takeaway for me is that if I’m deploying a rails app to tomcat then I will need to use an IDE that will let me test that deployment. IntelliJ anyone?