syntax sugar

Somehow I have a feeling this is going to be a regular occurance. I am talking of course about Ruby’s syntax sugar. How cool is it, to write basic English sentences and have them run as program code?

How about this beauty:

time = time - 1.day if time.hour < 7

It’s just too darn purty. Time is time minus one day if time’s hour is less than seven!

Artist blogs

Today appears to be the day where stuff gets done!

I just implemented a blog import tool for GO Magazine. Ruby and Rails just make it so easy. I generated two models: Blog and Post. Blog gets hooked up to an Artist, and Blog has_many :posts.

Blog is hooked up to a Link as well. Every day, I just traverse the Links, fetch the feed and parse it using Ruby’s built-in RSS Parser. Walk the items and insert them into the database, done!

I’m even surprised at the speed, tens of blogs are imported in a few seconds.

restful development

DHH is a smart man.

When I saw his keynote about crud/rest a while ago, I was sceptical. After all, writing controllers in Rails is not exactly a pain, anyway. Why change the current m.o. to use methods like put and delete, when they’re not even supported by browsers?

But restful development didn’t go away and I read more and more about it in the Rails community.

So after upgrading to 1.2.1 I decided to give it a go. And what do you know. It’s actually easier than regular development in Rails! I am telling you one day web applications will simply write themselves. Of course, this kind of sweetness would not be possible without convention over configuration, but still the Rails folks are definitely onto something.

I literally added one line to config/routes.rb and three–count ‘em–three–methods to the new controller. That’s all it took! I am amazed.

I’m still not refactoring my old controllers though. Well, not yet.

It's being used

Funny when something I’ve built actually gets used.

Last week I added a section called livesets to GO Magazine. Just a page where anyone can submit a live-deejay mp3 set. Of course anyone can then download the set, plus people can vote. Basic stuff.

Originally I wanted to use it just for myself, since people throw their livesets at me all the time.

But then I decided to mail this to the artists I know and what do you know? Now every day livesets are added, people are downloading and voting like crazy and I have lifted some gems off the net already! Flow’s liveset is great, as is the one by Ellen Allien.

acts_as_sluggable

How can anyone not love Rails?

Many websites these days have nice descriptive URLs like /post/12/i-like-doggies. Apparently it helps in the Google ranks, although I am not convinced.

In the olden days you would probably write a custom script, add a database column, knit the two together and use a little mod_rewrite magic to hide it all from the user. Ugly, brittle, cumbersome. That’s why I never bothered.

enter rails.

Installed the plugin acts_as_sluggable. Made one change to my article model and WHAM! url slugs like a pro.

It doesn’t get any sweeter than this.

dnsbl_check

Finally I have this blog to post some interesting tidbits about my rails plugin dnsbl_check.

First of all, I am glad to announce that the plugin will become part of Instiki! Comment spam is a huge problem for any publishing platform, but Wikis tend to suffer extra. My plugin does help a lot battling the zombies, plus it’s very low overhead, thus great for high-volume sites.

I am working on a new release of the plugin which will enable a “pre-check”. In other words you’ll know that the current client will be denied access even before the client submits a form! Based on this you can choose to bypass the filter, or augment it with a captcha.

The funniest thing is that just a few weeks ago, a seemingly innocent person was denied access via the plugin. This person contacted me and I was quite bummed… false positives are never good eh? But after investigation I noticed that he had actually sent out spam! Tee hee … ‘t works! The lesson learned: don’t spam if you want to contribute to my forum. Sweet.

I am testing the new version, but it will be a while before I am releasing this. The current version of the plugin works just fine.

Return-Path in Rails ActionMailer

So today I finally made Rails do something I needed for a long time: honour the Return-Path header on outgoing emails. This is basically the return address for MTAs, er, computers to use. It’s a quite useful header since you can manage your mailing list the proper way. I.e. have replies sent to you, but quota warnings and delivery faillures sent to a computer.

Rails would honor the Return-Path header, but then pass it off to Net::SMTP where it got lost.

I feared this would be a tough one to crack but the solution was tiny. It just took me a couple hours to figure it out, browsing the net/smtp.rb source.

I submitted the patch to the Rails repository just now and I expect it will be added to trunk (or as the Rails people say: “edge”). Should become available soon.