Hello, I’m a web craftsman with a passion for the modern web. I build web applications and play with social services and communities.

August 5, 2010 at 5:12 pm

When running rake tasks (that are related to the database) in Rails apps I ran into the following error a couple of times on different OS X Snow Leopard machines:

uninitialized constant MysqlCompat::MysqlRes

The mysql gem is installed but got compiled for a wrong architecture for some reason. I’m not 100% sure when this happens but if you run into the problem uninstall the mysql gem

$ sudo gem uninstall mysql

and reinstall it with this flag

$ sudo env ARCHFLAGS="-arch x86_64" gem install mysql

if you are using rvm you can skip the “sudo” on all commands.


January 26, 2010 at 5:14 pm

LocaNote LogoAbout a week ago I launched a new web service with a few friends from university. It’s called LocaNote. LocaNote is a cloud service that stores personal notes online. What’s special about LocaNote is that every note has a geographical location attached to it. Using this information LocaNote will show you only notes that are relevant to your current position. And since it is a cloud service you can take your notes with you on a mobile device. An iPhone App is in development right now and should be available on the App Store within the next few weeks. The built-in GPS receiver in the iPhone makes it the perfect mobile device for LocaNote. It will automatically use it’s current GPS-location to find notes that are really close to your actual position. Also, when you create a new note it will be placed on your current location.

The website and API is done in Ruby on Rails and the web frontend makes heavy use of the recently released jQuery 1.4.

LocaNote Screenshot

LocaNote Notes View


January 20, 2010 at 10:26 pm

Gravatar (globally recognized avatar) is an Avatar Service from Automattic, the company behind WordPress. It allows users to upload an avatar which is attached to an email address. This way developers all over the world can integrate “Gravatars” into their web services. All they need is a users email address. For the end-user this has the advantage that they have only one place for maintaining their avatars. Any change to their gravatar will immediately have an effect on all gravatar-enabled web services.

So how to implement Gravatar in your Ruby on Rails project?

One way would be to generate the URL to the gravatar manually.

Such a URL looks like this:

http://www.gravatar.com/avatar/3b3be63a4c2a439b013787725dfce802.jpg

The long combination of numbers and letters is a MD5 hash of the users email address.
So the Rails Code in your View could look like this:

<%= image_tag “http://www.gravatar.com/avatar/” + MD5::md5(“user@email.com”.downcase) + “.jpg” %>

Or since you are using Ruby why not go straight for a Rails Gem? “Gravtastic” does a good job here.

Just install the Gem and use

is_gravtastic!

in your User Model.

After that you have a new attribute “gravatar_url” available to any instance of “User”.


December 11, 2009 at 2:04 am

I spend the last couple of hours trying to get Ruby on Rails (2.3.5) to work with MySQL on Mac OS X 10.6 Snow Leopard. So far I have been using SQLite for Rails Development but a current project requires some MySQL specific functions. I didn’t expect things to be so rough but now everything works and I am quite happy. So happy that I decided to write it down and share it with the world.

First: What was the problem?

Since I’m coming from PHP/MySQL development I had XAMPP already installed on my system and I was hoping to use the same XAMPP-bundled MySQL Server I have been using for all my PHP projects for rails projects too. Forget it! Don’t waste your time here. You may get it to work somehow but you will run into trouble at some point since XAMPP’s MySQL is compiled in 32bit and Ruby on Snow Leopard in 64bit. So basically as soon as you have a Mac with a Core 2 Duo (or any other 64bit processor) and running 10.6 Snow Leopard you have to install a 64bit version of MySQL.

So the problem you will run into (or already ran in and that’s why you are here right now) while trying to install the mysql gem with sudo install mysql looks like this:

Building native extensions.  This could take a while…
ERROR:  Error installing mysql:
ERROR: Failed to build gem native extension.

/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lm… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lz… yes
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lsocket… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lnsl… no
checking for mysql_query() in -lmysqlclient… no
checking for main() in -lmygcc… no
checking for mysql_query() in -lmysqlclient… no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

and some more I won’t bore you with.

So here comes the solution:

1. Download MySQL 5.4 beta for Mac OS X 10.5 as x86_64 version from the official MySQL website

2. Open up the downloaded .dmg and run the mysql-5.4.x-…x86_64.pkg installer, followed by the MySQLStartupItem.pkg Installer. After that you install the MySQL.prefPane which allows you to start and stop the MySQL Server comfortably from the System Preferences (for some reason the prefPane is still in 32bit but that won’t bother us now).

3. Go into terminal and install the mysqlplus gem:

sudo gem install mysqlplus

4. That’s it!

It seems a bit crazy that I spend hours figuring that out but basically the key to success is mysqlplus here. I tried all kinds of combinations with the official MySQL 5.1/5.4, XAMPP’s MySQL, MacPorts MySQL and the standart mysql gem but none worked. Sometimes I got the mysql gem to compile and install but then rails still couldn’t connect to the database… However, now it works and I’m glad things can go on!