11 Jun 2007, 12:29pm

by Ariejan de Vroom
16 comments

ActiveScaffold, Acts_as_taggable_on_steroids

Update: also read Active Scaffold + Acts_as_taggable + Auto Completion.

This is kind of an advanced topic, but I think it may be useful to a lot of people.

ActiveScaffold is a great plugin to start building a user interface. The great thing about AS is, that is automatically recognizes associated models. When editing a model, you can easily add or select another model that you want to associate with is.

The best example of this is an Article, where you can select the author (the associated User model) with a drop down box.

There is only one point where I ran into trouble with ActiveScaffold: acts_as_taggable_on_steroids.

Acts_as_taggable_on_steroids allows you to easily attach tags to models and do all kinds of crazy stuff with them. But, if you want to integrate in into AcitveScaffold, you’re in for a tough ride.
more »

10 Jun 2007, 8:42pm

by Ariejan de Vroom
leave a comment

Find and Replace with a MySQL Query

There are times when you have a lot of data in a database (let’s say wp_posts for a Wordpress blog like Ariejan.net). When you need to find and replace certain strings, this can be a very tedious task. Find all posts containing the “needle” string and manually replace all these occurrences with “chocolate”. With about 200 posts, you can imagine how long this would take to do manually.

But, as I always say: “You’re a programmer! You should script the hell out of everything!”

So, I found this: MySQL has built-in support to find and replace! Just a simple query will do:

UPDATE wp_posts SET post_body = REPLACE(post_body, 'needle', 'chocolate');

That’s it. The entire table ‘wp_posts’ is searched and all occurrences of “needle” are replaced with “chocolate”. The query only took about a split second.

10 Jun 2007, 8:34pm

by Ariejan de Vroom
5 comments

Send mail with a BASH Shell Script

Like any good programmer, I try to automate the crap out of everything. If you have to do it more than once, I try to write a script for it.

This time I want to show you how you can easily send an e-mail from a BASH script. The idea is that you want the script to send out an email to notify a user that something has happened.
more »

10 Jun 2007, 4:12pm

by Ariejan de Vroom
leave a comment

Ultimate List of Ruby Resources

This is the first post, named “Ruby”, in a series of “Ultimate List of … Resources”. I’m going to compose several lists for different topics I encounter during my development work. To start, I begin with Ruby. Later, I will add “Ultimate Lists” about Ruby on Rails, Subversion, AJAX and some other topics.

Feel free to let me know if I missed an important resource. I’m also open to suggestions about other “Ultimate Lists”.

For now, you’ll have to settle for the “Ultimate List of Ruby Resources”.

more »

30 May 2007, 9:12am

by Ariejan de Vroom
5 comments

Trac, WebAdmin plugin and global configuration

As you may know I manage quite a few trac installations. A few days ago I upgrade my server from Ubuntu “Dapper Drake” 6.06 to Ubuntu “Feisty Fawn” 7.04. This also upgrade trac 0.9.x to 0.10.3.

I was happy, since trac 0.10.3 has many improvements over 0.9.x, but there was one thing I was not so happy about. After the upgrade, I upgraded all my trac installations and everything seemed to be okay, except for the WebAdmin plugin. Apparently it was not installed anymore.

What happened? After upgrading the trac package, the plugins directory was emptied. Well, just re-install the WebAdmin plugin for 0.10.x.
more »

29 May 2007, 4:36pm

by Ariejan de Vroom
5 comments

Installing RMagick Ruby Gem on Mac OS X 10.4.9

When you want to manipulate images with Ruby (or your Rails application) you’ll probably want RMagick installed. This is no easy feat on Mac OS X.

The official guide suggests installing X11 and using darwinports to install everything. This guide shows you how to easily install RMagick on you Mac OS X system. In this case I use Mac OS X 10.4.9.
more »

29 May 2007, 4:02pm

by Ariejan de Vroom
2 comments

Slow connections with ProFTPD

My shiny new VPS, which is running Ubuntu Linux, uses ProFTPD for FTP access. Today I noticed that setting up the connection takes about 5 to 10 seconds. This is really annoying when editing files through FTP.

So, I investigated and found that by default ProFTPD tries to revolve the hostname of the client in order to put that in the logs instead of a plain IP address. This lookup can take quite some time, let’s say 5 to 10 seconds, especially when the look up fails and you have to wait on a time-out.

It’s easy to stop ProFTPD from behaving like this by adding the following line to your proftpd.conf in /etc/proftpd:

IdentLookups off

Restart ProFTPD and you’ll have a fast FTP connection to enjoy!

21 May 2007, 1:37pm

by Ariejan de Vroom
5 comments

MERGE request failed on ‘/path/to/file’

After upgrading my Subversion server to Ubuntu Feisty, I noticed that when committing I got the following error:

svn: MERGE request failed on '/svn/repository/trunk'
svn: MERGE of '/svn/repository/trunk': 200 OK (http://svn.myserver.com)

Although the messages says that the commit failed, it has not. A simple ’svn update’ will merge the changes you made to the repository to your working copy again and you’re good to go.

So, what is the problem here? Are you by any chance running Trac? Did you install the post-commit hook to integrate Subversion with Trac? Right, so did I.

The problem here is that the trac-post-commit-hook script needs a few updates in order to include the proper modules. Take a look at the most recent 0.10.x version.

After updating the trac-post-commit-hook script, commits worked fine again. Such an easy fix for such a nasty problem.

9 May 2007, 11:23am

by Ariejan de Vroom
3 comments

Rails Snippet: Write like Orwell with to_sentence

A few weeks ago I posted an article that explained how to create a comma separated list from a hash of objects. When I was browsing the Rails API documentation I came across a method named to_sentence.

What this little bugger does is create a human readable, comma separated list of items in an array or hash. But the big difference here is that you can specify what the last separator must be. By default this is set to ‘and’. See the following example.

@users = User.find(:all)
@users.collect {|u| u.firstname}.to_sentence
=> "Tom, Dick, and Harry"

Of you course, you can specify the last separator, called the connector. Also it’s possible to not show the last comma.

@users.collect {|u| u.firstname}.to_sentence(:connector => "and of course,", :skip_last_comma => true)
=> "tom, Dick and of course, Harry"

I bet this will greatly simplify the way you list names, tags, categories or whatever else you want summed up in a comma separated list with a human touch.

12 Apr 2007, 11:04am

by Ariejan de Vroom
6 comments

Rails, Resources and Permalinks

There has been quite a bit of discussion about creating permalinks with a rails resource. In this article I will show you how to create permalinks for a resource named ‘pages’ without giving up on any of the resource goodness!
more »