JRuby and Rails - Part I
April 8th, 2010I have need of some Admin pages for a project I am working on and so decided I would try my hand at Rails. Ultimately I want to host these pages in the same container that I am using for the project so that means Jetty. I found a Jetty Rails project on rubyforge. I did some JFGI work and found lots of frankly confusing and contradictory advice. That lead me to Debian Ports, which didn’t load on my Snow Leopard install. Which lead me to Mac Ports, which did. I tried to build an existing Ruby Rails project that I “stole” from some colleagues, but that didn’t work out. After a chat with another friend which included a brief education on the difference between Ruby and JRuby I cleaned up the Mac Port installs, broke down and bought a book (JRuby on Rails). Good book, well written, and unfortunately (as I discovered) somewhat dated.
Thanks to Robert Dempsey’s post regarding JRuby installs on Mac. The link for the MySql connector is broken, look on the MySQL site instead. More JFGI led me to drop the ActiveRecord-JDBC gem and install activerecord-jdbcmysql-adapter (as described by Miro and Arun Gupta, and even better on the JRuby site). Still I was stuck in the starting gate as I could not get the db:migrate to execute.
Still I was getting: CreateProductCategories is not missing constant ProductType! What a horrible and wholly un-helpful error message. More JFGI. This post on MarkMail ultimately proved not to be helpful (at least in my situation). But it did change the error message I got to: Unknown key(s): ProductCategory, which gave me an idea.
In the end I modified the create_product_categories.rb file from:
%w(Computers Mysteries Science Fiction Crime).each do |v|
ProductCategory.create :product_type => book, :name => v
end
to:
%w(Computers Mysteries Science Fiction Crime).each do |v|
ProductCategory.create :product_type_id => book.id, :name => v
end
Now back to Chapter 4 and Unit Testing.