I’m working on a Rails 2 to Rails 3 upgrade (I know, just in time for Rails 4), and I’ve been annoyed by the fact that ActiveRecord kept spewing its log statements out to the terminal and not to the log file. After realizing this was not a commonly encountered problem, I realized the culprit was an old, out-dated plugin in vendor/plugins that was looking for a variable called RAILS_DEFAULT_LOGGER which no longer exists, and was then creating a new Logger that just writes to STDERR. Ditching the plugin solved my problem. Sane people probably remove / update their plugins first. For the rest of us, keep this in mind.

I just put iNaturalist.org on Ruby Enterprise Edition. Unfortunately, I’m really not seeing any savings in memory consumption, aside from the Passenger ApplicationSpawner taking up a few less MB. Kind of dissapointed.

However, installing REE on my Mac was slightly less trivial than I was led to believe. Suffice it to say the REE installer assumes you have dependent libs in /usr or /usr/local, and if you don’t, there aren’t any flags you can pass in to change that. However, you can set ENV vars, so I was able to get the installer to work like this:

export CC=gcc && export CXX=g++ && ./installer

Basically, the REE installer checks deps by using Ruby to write and compile a C file, but it’s default path to gcc was not the same as the gcc I normally use.

After that, I had to make sure all my gems were in place. I ended up installing rails, Hpricot, and ruby-debug (the latter 2 require compiled C) using REE’s own copy of rubygems, and I made sure the rest of our gems were vendorized. REE’s rubygems is just like normal:

/path/to/ree/bin/gem install rails ruby-debug hpricot

If you run into problems, make sure you’re tailing Apache’s error log and not just the Rails log, b/c that’s where Passenger will moan about its problems.

As I said, memory gains seem non-existent on our Ubuntu production machine, which is weird because I saw a 25% reduction in memory usage on my Macbook.

Active Record Model Adapters

I recently refactored some code in iNaturalist that fetches taxon names from external name providers like uBio and the Catalogue of Life. They return names and classification data that are similar but (of course) not identical to ActiveRecord models we use in iNat, so I figured I’d write adapters for them, and I thought a really smart solution would be to subclass the models themselves, simply overriding the attributes with getters that mined a private instance variable holding an XML response from one of the web services. Big mistake. ActiveRecord mixes in all kinds of magic into the models that doesn’t necessarily get passed on to child classes. I ran into all sorts of fun errors and problems until I remembered the Adapter implementation described here, which takes a much more sensible approach: don’t sublcass, and instead hold an internal copy of the adaptee, passing calls to anything you don’t want to override to the adaptee.

Read the rest of this entry »

In case you’re working through Developing Facebook Platform Applications with Rails, you might have run into problems with authenticity tokens and FBML forms.  Quick dumb fix to save you 2 seconds:

    action="<%= new_invitation_path %>"
    type="Karate Poke"
    content="YAYS I added this facebbok app">
      actiontext="Invite your friends to use Karate Poke"
    <%= hidden_field_tag :authenticity_token, form_authenticity_token %>