Posts tagged ruby on rails

Delayed Job dying silently

I’ve just completed migrating a client site from BackgrounDRb to delayed_job (which is a huge relief on several levels). I had hoped to complete the process this morning, but the delayed_job process kept dying on me without any apparent explanation in the usual logs.

Thankfully the RPM log in my app turned out to be capturing one vital detail — the MySQL server had “gone away”, Armed with that knowledge I was able to find this thread on github and from that Brandon’s pointer to the ‘reconnect’ option in database.yml. Setting that appears to have solved that last lingering problem.

And since it took a while to track down, it seemed worth sharing.

Character encodings, Rails 3 and Ruby 1.9.2

In a lengthy blog post detailing many of the intricacies and some of the politics relating to character encodings in Ruby, Yehuda Katz has a few paragraphs that left me more than a little excited:

The most common scenario where you can see this issue is when the user pastes in content from Microsoft Word, and it makes it into the database and back out again as gibberish.

After a lot of research, I have discovered several hacks that, together, should completely solve this problem. I am still testing the solution, but I believe we should be able to completely solve this problem in Rails. By Rails 3.0 final, Rails application should be able to reliably assume that POSTed form data comes in as UTF-8.

and

When using Rails 3.0 with Ruby 1.9.2-final, you will generally not have to care about encodings.

If it does indeed work out that way, that’s a whole category of bug reports I’ll finally be able to say goodbye to.

has_many_polymorphs and Rails 3

I’m gradually porting a number of my older Rails apps over to Rails 3. The main motivation is a chance to really put the new version through its paces, get a better sense of how it’s working, where plugins are at, etc; but it’s also rather nice to get some of the performance improvements and cleaner code along the way.

Catapult relies on Evan Weaver’s has_many_polymorphs plugin quite extensively so it was important to be have a Rails 3 compatible version. I couldn’t find any evidence that anyone else was working on it, so I’ve forked the github project and made a few alterations. I’ve set it up to work as a gem (so I can pull in the latest version using bundler) and adjusted to fit the new rails initialization process. It’s rather hacky, but it’s working for me so far.

Evan informs me that he has no plans to work on compatibility, so I’m going to see what time I can find to tidy it up a bit more, make sure the tests are passing, etc. If anyone else is so inclined, I’d love some help with that. You can find my fork on github.

Asset bundling in Rails

I stumbled across James Herdman’s piece on asset bundling in rails earlier this week. I’d always presumed you could do this but never got round to investigating as very few of my projects load in very large numbers of JS/CSS assets.

In the end it was quite timely as I’ve been trying to reduce the footprint of an app I’ve recently inherited that is using far too many plugins. With this technique it was very straightforward to remove the asset_packager library. Now, what else can I eliminate…?

Faster Rails development with bundler and rvm

If you’re anything like me, you’ve found the rails server and console taking longer and longer to launch lately. Even switching to Rails 3 for most active projects hasn’t really helped. But I finally found a solution a couple of weeks ago.

I found it reading Mikel Lindsaar’s Bundle Me Some Sanity where he outlines the way that bundler coupled with rvm allows a rather different and much cleaner way to manage gems in a ruby application.

I’d been aware of rvm as a way to cleanly manage different versions of ruby on a single machine, but had missed their (recent addition in 0.1.25 of) Named Gem Sets. With Named Gem Sets you can specify a version of ruby and a separate gem library for each app, reducing dependency resolution time considerably.

I already can’t imagine switching away from this.