More bits == better? AKA Snow Leopard broke my Gems

Snow Leopard install went fine.  Running methodbox after this didn’t.  ImageMagick, libxml and mysql gems were all broken.  Followed this advice to get it all working.  Boils down to re-install MacPorts, install ImageMagick and libxml2 from ports, re-install the RMagick and libxml-ruby gems, install mysql-64bit, re-install mysql gem (in 64 bit mode).

Easy!!  Only took 2 hours.  So that’s about 4 hours (and 2GB+ downloads) for the snow leopard upgrade so far!

Also found this script for installing ImageMagick.  I couldn’t get it to work but maybe you can.

There’s something good around the corner

Up until now we have been using images to fake rounded edges on divs etc.  This is fine until you want to change the styling and resize anything.  So, I had a look at doing it in pure CSS.  Luckily, so have lots of other people eg. Nifty Corners and Spiffy Corners.  I used the Spiffy Corners one since it comes with a nice code creator which saves lots of time and is easy to re-use.  All you have to do is enter in the class name for the CSS, colour of the bar and the background colour and it generates both the CSS and the html.  Job done.

Sorry for the delay – we’ve been on the rails

So it’s been a few months since the last post about adventures in flex.  The final verdict, quite nice but without more developer support the obesity-elab project was too big for one person.  So, we decided to go with the flow and follow the rails path like myExperiment and Sysmo.  This gave us a big codebase to play with.  We still needed some back end components to handle csv file parsing and creation so a jetty based webapp was created using the Ostermiller Utilities for the CSV handling. We (well, me) also used Apache solr with the ruby acts_as_solr plugin for searching the metadata.

Writing complex apps in html is certainly an interesting challenge and after having created the first version of what we now call methodbox I can see why frameworks like Google Web Toolkit and flex are so appealing.  Having to insert hidden objects into the html so the application can remember them between clicks gets a bit tedious after a while! However, we overcame a few hurdles along the way and here are some things I found useful:

Things I needed to know about Rails but was too much of a newby to find out from the books

1. routes.rb.  How to specify routes correctly.  Part of the functionality of methodbox is selecting multiple surveys and searching them.  I couldn’t get the app to return to the correct route after doing the search. Of course, I had not specified the route correctly.  So, if you are returning a collection you need something like this:

map.resources:surveys, :member => {:download => :get}, :collection => {:add_to_pseudo_cart => :get,  :data => :get, :datagrid => :get,:hide_info => :get, :more_info => :get, :search_variables => :get,:sort_variables => :get }  do |survey|

2. Check box tag.  Use check_box_tag to allow you to select multiple objects in the page and send them across inside a hash to the controller.

<%= check_box_tag “entry_ids[]”,,false, :class=>’survey_checkbox’ %>

where item is the object which you want to select or not, false means unchecked when created

3. Selecting, unselecting checkboxes programatically.  Lets say you want a gmail style select all, none (and an ‘invert’ selection – ie. select those not selected and vice versa).  Use link to function and some javascript like this:

<%= link_to_function ‘All’, “$$(‘input.survey_checkbox’).each(function(checkbox) { checkbox.checked = true; });” %>

<%= link_to_function ‘None’, “$$(‘input.survey_checkbox’).each(function(checkbox) { checkbox.checked = false; });” %>

<%= link_to_function ‘Invert selection’, “$$(‘input.survey_checkbox’).each(function(checkbox) { if (checkbox.checked == true) {checkbox.checked = false;} else {checkbox.checked = true; } });” %>

where ‘survey_checkbox’ is the class name of the check_box_tag (see 2 above).

4. XML creation and parsing.  Tried the various libraries but found libxml the fastest.  I needed to parse some fairly big (1 meg+) xml files which contained the metadata for the surveys we are using.  These surveys take the form

<metadata year="2000">
<description>BP Probs: No problems taking blood pressure</description>
<Label>Refusal (8)</Label>
<Label>Don't know (9)</Label>
<MissingValues>-99  thru -1</MissingValues>

Here is some sample code to parse (some of) this using libxml (don’t forget your require ‘xml’ bit):

parser = XML::Parser.file(‘metadata.xml’)
doc = parser.parse

nodes = doc.find(‘//metadata/variable’)

nodes.each do |node|
namenode = node.find(‘child::name’)
namecontent = namenode.first.content = namecontent

descnode = node.find(‘child::description’)
desccontent = descnode.first.content

catnode = node.find(‘child::category’)
catcontent = catnode.first.content

dernode = node.find(‘child::derivation’)
dercontent = dernode.first

dertype = dercontent.find(‘child::type’)
dertypecontent = dertype.first.content

dermethod = dercontent.find(‘child::method’)
dermethodcontent = dermethod.first.content

infonode = node.find(‘child::information’)
infocontent = infonode.first.content


5. gotAPI.  I used this online resource ‘a lot’.  A superb go to when the books are confusing or hard to navigate.

So, a few things which confused me and one major resource you really need.  See you on the Rails.