What we're listening to:
Jared

The Hold Steady:
Heaven Is Whenever
Jeff

Paper Route:
Absence

Today, I got bit by ActiveRecord race condition related to validates_uniqueness_of. Sometimes I just blindly trust that Rails is going to take care of things, and so it surprised me when I ended up with duplicate records in my database. A few people have written about this, and apparently it’s in the API Docs now, but I just hadn’t thought about it before.

The solution looks to be enforcing unique constraints at the database level.

By default I include the rails t.timestamps in my create table migrations. Always nice to know when a model has been created or updated, right? And what could it hurt?

Well, when they are in a join table for a habtm relationship they cause the associated records to be marked as readonly. This is because rails can’t save those extra timestamp attributes.

If timestamps or any other extra join information is needed, then use a join model instead with has_many :through.

more info

exception_notifier gotcha

July 22nd, 2008

Yesterday I was investigating why exception_notifier wasn’t, well, notifying me of exceptions.

I checked out the log, and I was getting an error like this:

ActionView::TemplateError (protected method `filter_parameters' called for #<Admin::ProductsController:0x2aaaaeccd6b0>)

Turns out Rails 2.1 breaks the version of exception notifier you get by running script/plugin install exception_notifier. To get the correct version, you have to run script/plugin install git://github.com/rails/exception_notification.git

Pretty lame, they really should update that.

form_builder tip

June 16th, 2008

I ran into a situation this week where I had a single partial containing form fields being rendered for different models. Inside that partial, one of the fields was a text_field_with_autocomplete, which presented a problem, since form_builder doesn’t know anything about text_field_with auto_complete, and the text field certainly needed to know what model we were working with here. After a little digging, turns out form_builder exposes a getter called object_name:

<%= text_field_with_auto_complete f.object_name, :city_name, ... %>

Easy.

A big topic at railsconf this year was hosting , deployment and scaling of apps. Talks and sessions on these topics were everywhere, not to mention Engine Yard getting pimped left and right (No, I won’t wear your tshirt). I found it extremely ironic then, when Michael Koziarski said in the closing keynote (paraphrased):

Deployment is a word you shouldn’t have to know.

I couldn’t agree more. I want to be as removed from the details of how to deploy and scale an application as possible. I want to focus on writing software that meets my customer’s needs, and the rest is details.

I think mod_rails is a big step in that direction. I think those guys are awesome, but I’m certainly not interested in writing improvements to garbage collectors to make ruby faster. It’s just not my bag. The more time I have to spend worrying about and managing deployment, the less time I’m spending “investing in myself” as DHH put it, and solving problems for my customers. It’s good to know that there are smart people out there working on how to scale applications, but I just don’t want to have to concern myself with it. Most of the apps I write are pretty small anyway, and when I meet the need to seriously scale, I’ll pay someone else to do it. Software like mod_rails is allowing me to survive even longer on a VPS (we use slicehost) so I can spend my time doing what I do best.

I moved my first VPS hosted slice over to phusion passenger (aka mod_rails) last night and was pleased so see the memory usage on my slice immediately drop about 15%. However, this morning I had lots of cryptic error messages about ruby_inline as follows:

Permission denied – /var/www/apps/mysite.org/releases/20080528201859/tmp/.ruby_inline/Inline_ImageScience_aa58.c
/usr/lib/ruby/gems/1.8/gems/RubyInline-3.6.7/lib/inline.rb:731:in `initialize’

I had already dealt with this issue when first setting up imagescience, and this looked related, but slightly different.

What I didn’t forsee was that previously, my mongrels were started with sudo – therefore running as root. When running with passenger, the user www-data was now the one that needed write access to the tmp directory, where rubyinline is doing its thing.

A quick permission change, then a restart with touch tmp/restart.txt and everything was green.

Overall, I’m really happy with the ease of setup and performance of passenger so far.

First Post!

June 3rd, 2008

Hot on the heels of RailsConf, I’ve decided to do something I’ve been meaning to do for a while, which is start a blog centered around rails, software, and business issues related to each of those and the rails community.

I’m going to start with some impressions and opinions I came away with at rails conf, coming up next . . .